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

Why does my teleport script stop working after a couple of uses?

I made a teleporter script and it works fine, until it doesn't. After a certain amount of uses it just stops working, and I can't figure out why. Any help?

The script »

local trigger = script.Parent.Parent.trigger
local destination = script.Parent.Parent.destination
local debounce = false

function onTouched(other)
	if debounce == false then
		debounce = true
		local rootPart = other.Parent:FindFirstChild("HumanoidRootPart")
		if rootPart ~= nil then
			--local changeBy = {trigger.Position.X - destination.Position.X, trigger.Position.Y - destination.Position.Y, trigger.Position.Z - destination.Position.Z}
			--rootPart.CFrame -= Vector3.new(changeBy[1],changeBy[2],changeBy[3])
			rootPart.CFrame = CFrame.new(destination.Position.X, destination.Position.Y, destination.Position.z)
			wait(1)
			debounce = false
		end
	end
end

script.Parent.Touched:Connect(onTouched)

1 answer

I think you should make the debounce true only if the rootpart is detected

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