I am trying to make a teleport service inside my game and everytime i step on a part to teleport I crash. Whats the problem?
Here is the code.
local teleport = game:GetService("TeleportService")
local part = script.Parent
local isData = {
crouch = false
}
part.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
teleport:Teleport(5660471859, player, isData)
end
end)
Any help?
Generally, for Touched events, you always want to use a debounce to prevent a code from running more than once. A way you can do it is like this:
local debounce = true
part.Touched:Connect(function(hit)
if not debounce then
return
end
debounce = false
--code here
wait(2) --Adding a delay to so it doesn't fire more than once.
debounce = true
end)
If you would like to view the documentation, it can be found here at the DevHub, where they provide more examples.