Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Teleporting system not working?

Asked by 4 years ago

I'm trying to make a teleport system to where players can 1v1 each other. Please help, thanks much! <3

01local mat = script.Parent --model with all the parts and scripts
02 
03local TPStart1 = mat.TPStart1 --part which one player has to stand on to get teleported
04local TPStart2 = mat.TPStart2 --part which another player has to stand on to get teleported
05local TPEnd1 = mat.TPEnd1 --endpoint part of player on TPStart1
06local TPEnd2 = mat.TPEnd2 --endpoint part of player on TPStart2
07 
08local bothReady = false
09local TP1Ready = false
10local TP2Ready = false
11 
12 
13TPStart1.Touched:Connect(function(hit)
14    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
15 
View all 37 lines...
0
Are there any errors? Galaxybombboy 134 — 4y
0
No Dehydrocapsaicin 483 — 4y

1 answer

Log in to vote
1
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:

01local mat = script.Parent --model with all the parts and scripts
02 
03local TPStart1 = mat.TPStart1 --part which one player has to stand on to get teleported
04local TPStart2 = mat.TPStart2 --part which another player has to stand on to get teleported
05local TPEnd1 = mat.TPEnd1 --endpoint part of player on TPStart1
06local TPEnd2 = mat.TPEnd2 --endpoint part of player on TPStart2
07 
08local bothReady = false
09local TP1Ready = false
10local TP2Ready = false
11 
12local readyEvent = Instance.new("BindableFunction")
13 
14TPStart1.Touched:Connect(function(hit)
15    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
View all 36 lines...

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.

Ad

Answer this question