Answered by
4 years ago Edited 4 years ago
The issue is line 35. You only check if both variables are true once. To circumvent this, you should either set up a while wait loop (which is considered polling and therefore inefficient) or you can take the more efficient route and use a BindableFunction
.
When a BindableFunction
objects :Invoke()
method is called, it will run the function you bind to it when you do BindableFunction.OnInvoke = someFunction
. :Invoke()
will also pass over any arguments to the function parameters as well.
Here is the completed script:
01 | local mat = script.Parent |
03 | local TPStart 1 = mat.TPStart 1 |
04 | local TPStart 2 = mat.TPStart 2 |
05 | local TPEnd 1 = mat.TPEnd 1 |
06 | local TPEnd 2 = mat.TPEnd 2 |
08 | local bothReady = false |
12 | local readyEvent = Instance.new( "BindableFunction" ) |
14 | TPStart 1. Touched:Connect( function (hit) |
15 | local humanoid = hit.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
18 | if humanoid and bothReady then |
19 | local rootPart = humanoid.Parent:WaitForChild( "HumanoidRootPart" ) |
20 | rootPart.CFrame = CFrame.new(TPEnd 1. Position) |
24 | TPStart 2. Touched:Connect( function (hit) |
25 | local humanoid = hit.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
28 | if humanoid and bothReady then |
29 | local rootPart = humanoid.Parent:WaitForChild( "HumanoidRootPart" ) |
30 | rootPart.CFrame = CFrame.new(TPEnd 2. Position) |
34 | readyEvent.OnInvoke = function () |
35 | bothReady = TP 1 Ready and TP 2 Ready |
I must remind you that I see multiple issues with your code. It has a high likelihood of being anywhere from very buggy to completely dysfunctional. I have only fixed your issue and nothing else.