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 » Scripting Helpers
Home Search
 

Re: when my "if" statement isn't true the script just breaks

Previous Thread :: Next Thread 
MilkyWay01 is not online. MilkyWay01
Joined: 22 Feb 2010
Total Posts: 1049
25 May 2013 10:37 PM
I'm currently making a horse racing game. In the game the player can unlock new horses and when they buy a certain one they get a value called "SpeedHorse" inserted under "Player." this part works perfectly. The problem is if the player tries to click on the gui and become a horse that they haven't unlocked, meaning they don't have the value "SpeedHorse", my script just breaks. After the script breaks even if they have the value it doesn't work. Output always says something like "SpeedHorse isn't a member of player even disconnected because of exception" How can I get around this problem? Here is one of the many scripts that gets activated when someone tries to be this certain horse.


function onClicked()
if script.Parent.Parent.Parent.Parent.Parent.SpeedHorse.Value == true then
-- I put the above line in to check to see if the value is there, this is where it breaks --if it isn't true

Player = script.Parent.Parent.Parent.Parent.Parent.Character
for _,v in pairs(Player:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency=1;
end end
if Player:findFirstChild("Torso"):findFirstChild("roblox") == nil then return end
Player:findFirstChild("Torso"):findFirstChild("roblox"):remove()
end
--sometimes i make the above end "else return end" and I get the same result
end
script.Parent.MouseButton1Click:connect(onClicked)
Report Abuse
COMMANDERREX12345345 is not online. COMMANDERREX12345345
Joined: 18 Jun 2009
Total Posts: 1316
25 May 2013 10:45 PM
if not game.Workspace.Part then
Instance.new("Part")
Report Abuse
MilkyWay01 is not online. MilkyWay01
Joined: 22 Feb 2010
Total Posts: 1049
25 May 2013 10:47 PM
What?
Report Abuse
COMMANDERREX12345345 is not online. COMMANDERREX12345345
Joined: 18 Jun 2009
Total Posts: 1316
25 May 2013 10:55 PM
try using:
else if not then------if *it* not then
That should do it.
Report Abuse
MilkyWay01 is not online. MilkyWay01
Joined: 22 Feb 2010
Total Posts: 1049
25 May 2013 10:58 PM
Here is the new script I tried


function onClicked()
if script.Parent.Parent.Parent.Parent.Parent.SpeedHorse.Value == true then
Player = script.Parent.Parent.Parent.Parent.Parent.Character
for _,v in pairs(Player:GetChildren()) do
if v:IsA("BasePart") then
v.Transparency=1;
end end
if Player:findFirstChild("Torso"):findFirstChild("roblox") == nil then return end
Player:findFirstChild("Torso"):findFirstChild("roblox"):remove()
else if not then
end
end
end
script.Parent.MouseButton1Click:connect(onClicked)

Output said unexpected symbol near then
Report Abuse
COMMANDERREX12345345 is not online. COMMANDERREX12345345
Joined: 18 Jun 2009
Total Posts: 1316
25 May 2013 11:55 PM
else
if not Player.Torso:findFirstChild("roblox")
then
Player.Torso:findFirstChild("roblox"):remove()
end
end
end
script.Parent.MouseButton1Click:connect(onClicked)



Try adding, or deleting some of the 'ends'
Report Abuse
MilkyWay01 is not online. MilkyWay01
Joined: 22 Feb 2010
Total Posts: 1049
25 May 2013 11:59 PM
Thanks commander, I never got to try out ur last suggestion but I fixed it on my own. It was orinally a book value but I changed it to a number value. Then the second the person joins the game they get it but its at 0. And the script that used to add the book value now just changed the number value to one. Then the script above just wants the number value to be greater than zero instead of true and for some magical reason when the number value isn't greater than 0 the script doesn't break anymore
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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