Script Timeout Exhaust Time

Whenever I run my game, either from Roblox Studio or from Roblox itself, my script will freeze then print Script Timeout in the output. here is the script.

local PlayersInQue = {}

wait(5)

while true do

script.Parent.Touched:Connect(function(Touched)
if Touched.Parent:FindFirstChild(“Humanoid”) then
local RootPart = Touched.Parent:WaitForChild(“HumanoidRootPart”)
RootPart.Position = game.Workspace.Queue.TP.CFrame.Position
table.insert(PlayersInQue,Touched.Parent)

	local Timer = Instance.new("NumberValue")
	Timer.Parent = game.ReplicatedStorage
	Timer.Name = ("Timer")
	Timer.Value = 60
	local Fire = game.ReplicatedStorage.Fire
	Fire:FireAllClients()
	wait(60)
	local TeleportService = game:GetService("TeleportService")
	local EscapeRoomID = 5941082483
	local ReservedServerCode = TeleportService:ReserveServer()
    TeleportService:TeleportToPrivateServer(EscapeRoomID, ReservedServerCode, PlayersInQue)  
end
end)
end

wait(5)

It freezes my game then stops running. This is 100% my script, with some help from devforum, and not open source, so it isnt some hidden virus in the game

My script is also using a remote event for the time countdown, so the counting down is not happening in the freezing script

You need debounce my dude. The touch physics in roblox aren’t perfect, so if you touch on a block or something it gets printed like a couple hundred times.

Ok, I am going to add a 1 second debounce and see what happens. It was working fine until i implented the timers

Always use debounce for touch events-especially when the touched part can be touched multiple times.

This is not good at all. The freezing is happening when i LAUNCH, before the function even happens.

i added some debounces too inbetween the touched and teleport

send your improvised script pls

Ok. I may have located the issue. The While True Do loop at the beginning must have been firing many many times, and due to that, it must have ran the script many times before it needed to which caused lag. I just removed the while true do and it worked, so i am going to add in the while true do somewhere else

It is working now, but i need to add some debounces because i was seeing some repeated printings

thanks for the debounce tip btw