Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleport crashes for some reason?

I made very cool epic script that teleports players to a second place, for my cool gun game, but instead of teleporting it crashes the game?

local TeleportService = game:GetService("TeleportService")
local Place = (6018067182)


script.Parent.Touched:connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		TeleportService:Teleport(Place, player)
	end
end)

does anybody know why this happens?

1 answer

✓ Accepted answer

Add a debounce; when you touch the brick you're sending multiple requests; therefore, crashing the game.

local TeleportService = game:GetService("TeleportService")
local Place = (6018067182)
local Debounce = false

script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  
    if player and not debounce then
	debounce = true
        TeleportService:Teleport(Place, player)
	wait(2.5)
	debounce = false
    end
end)

hydrogyn

This discussion is preserved as it was. New answers, comments, and votes are closed.