So I've been working on a story game, and I had released it today. But when I play with friends, I can't, because the game crashes for everyone when teleporting. It's become quite an issue, and I can't seem to figure out why it happens.
The script:
local truck = game.Workspace.Chapter1Lobby.Chapter1Truck
local Seats = truck.Chapter1TeleportSeats:GetChildren()
local exitGui = script.Parent:FindFirstChild("ExitButton")
local debounce = false
local event = game.ReplicatedStorage:WaitForChild("SendPlayersToChapter1")
local loadingscreen = script.Parent:FindFirstChild("LoadingScreen")
local plrs = {}
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
table.insert(plrs, player)
for i, emptySeat in pairs(Seats) do
if emptySeat.Occupant == nil then
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpPower = 0
player.Character.HumanoidRootPart.CFrame = emptySeat.CFrame
exitGui:Clone().Parent = player.PlayerGui
break
end
end
end
end)
-- happens somewhere in this block of code if im correct
event.Event:Connect(function(place)
debounce = true
wait()
if #plrs > 0 then
local tpService = game:GetService("TeleportService")
local code = tpService:ReserveServer(place)
wait()
for i, v in ipairs(plrs) do
tpService:TeleportToPrivateServer(place, code, {v})
wait()
table.remove(plrs, i)
wait()
end
end
wait()
debounce = false
end)
Please help!
Edit: So I've seen some of the answers, and I think some clearing up needs to be done. First of all, there is NO ERROR in the script. My issue is that the client hangs upon teleporting, thus preventing them from getting into the actual chapter.
Also, I am not much of an experienced scripter. I started scripting back in March, and I have learned a LOT since, but I will occasionally need an example script to do things. My script above is just an edited version of the script in this video: https://www.youtube.com/watch?v=27nHlMvmbek (skip to 7:29)
SOLVED!
Ok, so turns out the problem was Moon Animator. Disabling it when no longer needed fixed the issue! Thanks for all your suggestions anyways!

5 comments
I forgot to say that the thing that worked for me is making debounce true from start and doing if not debounce then return end then i set debounce to false then i set it to true and it works fine for me.
sry for the late reply, i had to go somewhere, but how do i fix the game hanging?? i mean, thank you for the debounce stuff, i guess, but how do i fix the game hanging?
i tried teleporting them one by one but it still hanged
hmm what do you mean by hanging do you mean it takes forever to load?
Oh i see. Try using a wait on for i, emptySeat in pairs(Seats) i dont think thats ocassionally the problem i think it may be the server usage.