|
| 28 Feb 2013 06:23 PM |
I made a script where when the button is clicked, the script is suppose to find all the spawns in Workspace and change their teamcolor to Bright Green.
The problem is, the script breaks if one of the spawns are not in Workspace. How can I make it check to see if any of the spawns are in Workspace, and if not, then skip to see if the next spawn in Workspace.
HEre is the script:
function finishraidspawns()
game.Workspace.RAIDBox.One.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Two.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Three.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Four.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Five.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Six.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Seven.TeamColor = BrickColor.new("Bright green")
game.Workspace.RAIDBox.Eightb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Nineb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Tenb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Elevenb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Twelveb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Thirteenb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Fourteenb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Fifteenb.TeamColor = BrickColor.new("Bright green") game.Workspace.RAIDBox.Sixteenb.TeamColor = BrickColor.new("Bright green") end
function finishctfspawns()
game.Workspace.CTFBox.One.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Two.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Three.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Four.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Five.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Six.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Seven.TeamColor = BrickColor.new("Bright green")
game.Workspace.CTFBox.Eightb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Nineb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Tenb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Elevenb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Twelveb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Thirteenb.TeamColor = BrickColor.new("Bright green") game.Workspace.CTFBox.Fourteenb.TeamColor = BrickColor.new("Bright green") end
function finishsftspawns()
game.Workspace.SFT.One.TeamColor = BrickColor.new("Bright green") game.Workspace.SFT.Two.TeamColor = BrickColor.new("Bright green") game.Workspace.SFT.Threeb.TeamColor = BrickColor.new("Bright green") game.Workspace.SFT.Fourb.TeamColor = BrickColor.new("Bright green") end
script.Parent.MouseButton1Down:connect(function() finishraidspawns() finishctfspawns() finishsftspawns()
end)
|
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Mar 2013 09:08 PM |
I'm not terribly experienced, but you may have better luck with using FindFirstChild() for each of them, and if it returns nil then have it not do anything for that specific one.
How you have it set now is completely static: it tries to change a very specific part with a very specific place, and if one is missing then it fails, because it doesn't exist. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2013 09:15 PM |
function finishraidspawns()
local Workspace.RAIDBox:FindFirstChild(One) = One
if One then One.TeamColor = BrickColor.new("Bright green") end
That would do it for just the first spawn. Just add in that set, and add a new one for each spawn. A little bit more messy than I think some people might respond with, but that should do it. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2013 09:39 PM |
NamesToIgnore = {"BLA", "BLA", "BLA"} -- until later on
for _, Child in pairs(game.Workspace.RaidBox:GetChildren()) do if function() for _, ChildChild in pairs(NamesToIgnore) do if Child.name == ChildChild return false end end then Child.BrickColor == BrickColor.new("Bright green") end end
Something like that...
|
|
|
| Report Abuse |
|
|
|
| 03 Mar 2013 01:11 PM |
@Daneel
I'm getting this output error:
Players.ROBLOXHAMTAH.PlayerGui.AdminPanel.Maps.RunMap:42: unexpected symbol near '.'
Here is line 42:
local Workspace.RAIDBox:FindFirstChild(One) = One |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 03 Mar 2013 02:43 PM |
| it may not help but.make it "one = blah blah" |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Xnite515
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 22763 |
|
| |
|
|
| 03 Mar 2013 07:25 PM |
| You could put an "if statement" for every single one. Or you could just make sure they are always in the workspace. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2013 08:03 PM |
I got the local backwards. Started typing it like that yesterday for some reason and made the error more than once.
It's local One = Workspace.RAIDBox:FindFirstChild(One) |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
| |
|
|
| 04 Mar 2013 02:45 PM |
@daneel
Output:
Raidbox is not a valid member of Workspace |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2013 02:46 PM |
| Ugly code, too long, don't read. |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2013 06:44 PM |
I tried this but it says "Argument 1 missing or nil"
function finishraidspawns() local Raidbox = Workspace:FindFirstChild(RAIDBox)
if Raidbox then
local One = Workspace.RAIDBox:FindFirstChild(One)
if One then One.TeamColor = BrickColor.new("Bright green") end end
function finishctfspawns() local ctfbox = Workspace:FindFirstChild(CTFBox)
if ctfbox then
local One = Workspace.CTFBox:FindFirstChild(One)
if One then One.TeamColor = BrickColor.new("Bright green") end end |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2013 07:23 PM |
| http://wiki.roblox.com/index.php/WaitForChild |
|
|
| Report Abuse |
|
|