I am building an airport, and I want players on an "airline" to be teleported to a location at the right time.
I have a functioning countdown timer and ticket system, that sets a leaderstat to "ACA" when you use a ticket. It was originally a BindableEvent, but BindableEvents can't return things, I think, so I switched to a BindableFunction.
BindableFunctions make things worse, because they stop a loop cycle for the count down. It's basically a while true do loop that subtracts 1 each time, then goes back to 120.
Here's what the function does:
script.TeleportACA.OnInvoke:connect(function()
for i,v in pairs (game.Players:GetChildren()) do
if v.leaderstats.Stage.Value == "ACA" then
v.Character.Torso.CFrame = CFrame.new(Vector3.new(562.997, 24.732, -218.065))
v.TeamColor = BrickColor.new("Pink")
v.leaderstats.Stage.Value = "Racing"
v.Resources.AirportTicket.Value = " "
else
print ("hi")
end
end
end)
The BindableFunction ends up stopping the entire loop cycle for Air Canada. As seen in this picture.
This is the loop cycle this function is stopping. I used threads so the rest of the loop cycle is OK. This is the part that isn't working.
spawn(function()
while times.AirCanada.Value > -1 do
wait (1)
times.AirCanada.Value = times.AirCanada.Value - 1
if times.AirCanada.Value == 0 then
eventhandler.TeleportACA:Invoke()
times.AirCanada.Value = 120
end
end
end)
Any help is appreciated, thank you!
