generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to skip if something isnt found

Previous Thread :: Next Thread 
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
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
iDerpyDogez is not online. iDerpyDogez
Joined: 05 Feb 2012
Total Posts: 1781
12 Jul 2016 02:45 PM
pcall(function() -- code here -- end)


#code --[[ hi friends i like turtles ]]--
Report Abuse
kools is not online. 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 is not online. 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 is not online. 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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
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 is not online. 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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
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 is not online. 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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
13 Jul 2016 05:07 AM
so basically how do I check if something isn't in a certain place


Report Abuse
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
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 is not online. 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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
13 Jul 2016 05:10 AM
Yeah I tried that and I got that error :(


Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
13 Jul 2016 05:11 AM
Post the whole script?


Report Abuse
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
13 Jul 2016 05:12 AM
That's the only bit that matters and where the error is


Report Abuse
DevVince is not online. 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
TheM0rt0nator is not online. TheM0rt0nator
Joined: 16 Aug 2014
Total Posts: 387
13 Jul 2016 05:16 AM
Thank you for trying :)


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image