I have a problem with these Teleporter Scripts, which teleport the Player from Brick A to Brick B. They usually work but have like a 20% chance of breaking when touching. Here is the script, the Hitbox (around the Heart) and the Video where i tried teleporting but it broke…
local Teleport = “Telemsion Kampf 1 (3)” --Put the name of the Part between the ""s.
function Touch(hit) --Indicates that the Part has been Touched.
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true --Checks Debounce.
local Pos = script.Parent.Parent:findFirstChild(Teleport) --Gets the Part to teleport to.
hit.Parent:moveTo(Pos.Position) wait(2) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end --Takes you there and Ends the Function.
script.Parent.Touched:connect(Touch) --Listens out for Touchers.
local Teleport = "Telemsion Kampf 1 (3)" --Put the name of the Part between the ""s.
local debounce = false
local TelePart = script.Parent.Parent:FindFirstChild(Teleport)
script.Parent.Touched:Connect(function(part)
if debounce == false then
debounce = true
local Character = nil --._.- Sanity Check to see if Player hit button
local Player = nil
if part.Parent:IsA("Model") then
Character = part.Parent
elseif part.Parent.Parent:IsA("Model") then
Character = part.Parent.Parent
elseif part.Parent.Parent.Parent:IsA("Model") then
Character = part.Parent.Parent.Parent
end
if game.Players:GetPlayerFromCharacter(Character) then
Player = game.Players:GetPlayerFromCharacter(Character)
Character:MoveTo(TelePart.Position)
end
wait(3) -- Delay of how long it takes to reactivate the teleporter.
debounce = false
end
end)
I think the problem you had was that you did not do sanity checks on if the teleported Object was an actual player.
i think the problem is you trying to use locked as a debounce
local Teleport = “Telemsion Kampf 1 (3)” --Put the name of the Part between the ""s.
function Touch(hit) --Indicates that the Part has been Touched.
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then
script.Parent.Locked = true
script.Parent.Parent:findFirstChild(Teleport).Locked = true --Checks Debounce.
local Pos = script.Parent.Parent:findFirstChild(Teleport)--Gets the Part to teleport to.
hit.Parent:moveTo(Pos.Position)
wait(2)
script.Parent.Locked = false
script.Parent.Parent:findFirstChild(Teleport).Locked = false
end
end --Takes you there and Ends the Function.
script.Parent.Touched:connect(Touch) --Listens out for Touchers.
also local script.Parent cuz it took me a bit to figure out what it is without that touch event
also im pretty sure this is enough
local part = script.Parent
local part2 = workspace.Part2
local debounce = false
part.Touched:connect(function(hit)
if hit.Parent:IsA("Model") and not debounce then --checks if its a model and if debounce
debounce = true
local playerCharacter = hit.Parent
playerCharacter:MoveTo(part2.Position)
wait(2)
debounce = false
end
end)
also are you sure that part.locked is doing its job right?
part.locked is a property used to lock parts so you cant click on it in studio
it has no real debounce in real gameplay
below is what locked does just incase you didnt know
better safe than sorry
hope this devforum post helps you (its about debounce so if you already know it then you might not want to read it)