|
| 12 Jul 2016 02:11 PM |
I know this is really basic but how would I skip some code if something isn't found. In my script it has this line:
if v:FindFirstChild("Team").Value == "Blue" then
but if a new player joins they don't have a value called team in their player, so it breaks the script. How do I fix this.
|
|
|
| Report Abuse |
|
|
|
| 12 Jul 2016 02:45 PM |
pcall(function() -- code here -- end)
#code --[[ hi friends i like turtles ]]-- |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 12 Jul 2016 02:52 PM |
Something being found isn't the correct way to describe what is going on here. The player does have a Team property (it's not a child this is a very important distinction!) but it is what is called nil.
if v.Team == BrickColor.Blue() then -- is a more accurate way to do what you want I believe.
Unless Team isn't really the Team property of player and BrickColor instance ...
|
|
|
| Report Abuse |
|
|
fghik
|
  |
| Joined: 06 May 2008 |
| Total Posts: 3288 |
|
|
| 12 Jul 2016 03:35 PM |
Perhaps try something like this?
if (v:findFirstChild("Team") == nil) then print("NO VALUE!") return end if v:FindFirstChild("Team").Value == "Blue" then |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Jul 2016 03:37 PM |
*facepalm*
if v:FindFirstChild('Team').Value == 'Blue' then --do something else --if this is false --do something else end
|
|
|
| Report Abuse |
|
|
|
| 12 Jul 2016 03:38 PM |
shhh it was tricky because i removed the team value at the end of the round...but fixed now
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Jul 2016 04:01 PM |
mort you dont need to use a value to specify what team the player is on. Just use player.Team
|
|
|
| Report Abuse |
|
|
|
| 12 Jul 2016 04:04 PM |
But I'm not using the built in roblox team thing...im just setting a value to what team they are and then having a billboard gui above their head saying red or blue
|
|
|
| Report Abuse |
|
|
|
| 13 Jul 2016 05:03 AM |
I still don't know how to do this. My code is:
if game.Workspace.MusicParts[player.Name] then else local musicpartclone = serverstorage.Trackers:WaitForChild("MusicPart"):Clone() musicpartclone.Name = player.Name musicpartclone.Parent = game.Workspace.MusicParts end
but this gives an error because if there isn't a thing in music parts called the players name it breaks the script. But I want to just bypass it if it isn't in music parts.
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Jul 2016 05:07 AM |
--Try this? if not game.Workspace.MusicParts[p.Name] then local mp = serverstorage.Trackers:FindFirstChild'MusicPart':Clone() if mp then mp.Name = p.Name mp.Parent = workspace.MusicParts end end
|
|
|
| Report Abuse |
|
|
|
| 13 Jul 2016 05:07 AM |
so basically how do I check if something isn't in a certain place
|
|
|
| Report Abuse |
|
|
|
| 13 Jul 2016 05:08 AM |
Nope :(
11:08:26.701 - Player1 is not a valid member of Model 11:08:26.702 - Script 'Players.Player1.Backpack.BoomboxScript', Line 13 11:08:26.702 - Stack End
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Jul 2016 05:09 AM |
--derp
if not workspace.MusicParts:FindFirstChild(p.Name) then local mp = serverstorage.Trackers:FindFirstChild'MusicPart':Clone() if mp then mp.Name = p.Name mp.Parent = workspace.MusicParts end end
|
|
|
| Report Abuse |
|
|
|
| 13 Jul 2016 05:10 AM |
Yeah I tried that and I got that error :(
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
| |
|
|
| 13 Jul 2016 05:12 AM |
That's the only bit that matters and where the error is
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Jul 2016 05:14 AM |
Too bad I won't help you then, well I can't i'm missing information to help you fix the problem anyways.
|
|
|
| Report Abuse |
|
|
| |
|