|
| 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 |
|
|
|
| 25 May 2013 10:45 PM |
if not game.Workspace.Part then Instance.new("Part") |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 May 2013 10:55 PM |
try using: else if not then------if *it* not then That should do it. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|