How do I add debounce to this script so it doesn't reptitvaly trigger? I never learned debounce.
script.Parent.Touched:connect(function(hit) h = hit.Parent:FindFirstChild("Humanoid") if (h ~= nil) then m = Instance.new("Message") m.Text = "Press 'V' to climb the ladder" m.Parent = Workspace end end)
local debounce = false local timeBetween = 5 --The time in seconds that the message will stay for. script.Parent.Touched:connect(function(hit) if debounce then --If the debounce is enabled return nil --End the function end debounce = true --Enable the debounce h = Game.Players:GetPlayerFromCharacter(hit.Parent) --Get the player. if (h ~= nil) then --If the part that touched was part of a Player then m = Instance.new("Message", Workspace) --Make a message (should probably be in Player's PlayerGui) m.Text = "Press 'V' to climb the ladder" wait(timeBetween) --Wait for the length of the "timeBetween" variable debounce = false --Disable the debounce m:Destroy() --Destroy the message end end)
local db = false script.Parent.Touched:connect(function(hit) if db then return end if hit.Parent:FindFirstChild("Humanoid") then local m = Instance.new("Message", Workspace) m.Text = "Press 'V' to climb the ladder" db = true wait(3) db = false end end)
debounce = true script.Parent.Touched:connect(function(hit) h = hit.Parent:FindFirstChild("Humanoid") if (h ~= nil) then m = Instance.new("Message") m.Text = "Press 'V' to climb the ladder" m.Parent = Workspace debounce = false wait(5) debounce = true end end)
Forgive me if I'm wrong, I'm not that good at this.