Answered by
8 years ago Edited 8 years ago
Your Problem
Your code is a bit sloppy, but you only have 1 real error. This would be your second if statement
, on line 12.
What's happening is the script is reading over the first if statement, and if it passes then it will teleport you. BUT - the second if statement is always being read last and henceforth you will always be teleported to the second _PadValue.
How to fix
You can fix this by replacing the second if statement with an elseif
statement. This will make it so that the second condition will only be checked if the first one has not passed.
Notes
'elseif' statements do not require a second 'end' statement.
Define variables that are static on the outside of your event. This is more efficient because then they are not being defined everytime the event is called.
Gui buttons run on the client, so you can always index LocalPlayer
from game.Players
to retrieve the client. But this can only be done in a LocalScript. I don't want to break your code so you can implement this later if you'd like.
Tab your code correctly, it keeps it clean and legible.
Remove
is deprecated, use Destroy
:)
Code
01 | local player = game.Workspace:FindFirstChild(script.Parent.Parent.Parent.Name) |
02 | local court = script.Parent.Parent.Parent.Court.Value |
03 | local courtfind = game.Workspace._Court 1 |
05 | script.Parent.Join.MouseButton 1 Click:connect( function () |
06 | for i,v in pairs (courtfind._Team 1 :GetChildren()) do |
08 | local pad = tostring (v) |
09 | local padVal = v.Values._PadValue.Value |
10 | local padTaken = v.Values._PadTaken.Value |
11 | local tor = player.Torso |
15 | tor.CFrame = CFrame.new(v.tpspot.Position) |
16 | elseif padVal = = 2 then |
17 | tor.CFrame = CFrame.new(v.tpspot.Position) |
20 | script.Parent:Destroy() |