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

Teleport crashes for some reason?

Asked by 3 years ago

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

Log in to vote
0
Answered by
Hydrogyn 155
3 years ago

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

Ad

Answer this question