I'm trying to make an elevator work when I click a button. The only way it should work is if the player is touching the platform of the elevator while clicking the button. So if the player clicks the button without touching the platform then the elevator should not work. I'm having an issue with the touched event constantly being active. When I run the game the button works as it should. Afterwards the button works every time even though I may not be on the platform. Is there some sort of way to reset the touched event so that it turns on or off?
Here is my code:
local function onTouched() if not debounce then debounce = true clicker1.MouseClick:Connect(function(player) local Character = player.Character Character:SetPrimaryPartCFrame(teleport2.CFrame) end) wait(2) debounce = false end end Elevator.Touched:Connect(onTouched)
you can use ~~~~~~~~~~~~~~~~~ script.Disabled = true ~~~~~~~~~~~~~~~~~ to disable the script and then the opposite to enable it
Your Touched Event is continuously running because it is being touched by another part. You didn't check if a player is touching it.
local function onTouched() local humanoid = script.Parent:FindFirstChild("Humanoid") if humanoid and not debounce then debounce = true clicker1.MouseClick:Connect(function(player) local Character = player.Character Character:SetPrimaryPartCFrame(teleport2.CFrame) end) wait(2) debounce = false end end Elevator.Touched:Connect(onTouched)
I'm not quite sure this work but try it