My code works but I don’t understand how my debounce works. I’ve tried to replace the remote event with a remote function and send data to the event but it didn’t work compared to this code. How does the debounce also pause the script that fires the local script? How does this work?
Local script that moves the trash can:
local debounce = false
game.ReplicatedStorage.Events.TrashEvent.OnClientEvent:Connect(function(touch)
if not debounce then
debounce = true
for i = 1,30 do
task.wait()
local flap = touch:GetPivot()
touch:PivotTo(flap * CFrame.Angles(0,0,math.rad(3)))
end
task.wait(3)
for i = 1,30 do
task.wait()
local flap = touch:GetPivot()
touch:PivotTo(flap * CFrame.Angles(0,0,math.rad(-3)))
end
debounce = false
end
end)
Server script that fires the local script(there is also a remote function to identify an instanced tool):
local touch = workspace.Trash.Layer
touch.ClickDetector.MouseClick:Connect(function(plr)
game.ReplicatedStorage.CreateWeldFunction.OnServerInvoke = function(plr,name)
if name == "Food" then
return true
else
return false
end
end
plr.Backpack:ClearAllChildren()
game.ReplicatedStorage.Events.TrashEvent:FireClient(plr, touch)
end)