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)
