I’m learning scripting and I’m having trouble making the debounce. If you add suggestions/feedback to make it so the debounce works that would be greatly apprieciated.
local part = script.Parent
local debounce = false
local function whenTouched()
if not debounce then
end
debounce = true
local newPart = Instance.new("Part",game.Workspace)
newPart.Size = Vector3.new(1,1,1)
newPart.BrickColor = BrickColor.new("Electric blue")
newPart.Position = Vector3.new(0,0,0)
newPart.Anchored = false
debounce = false
end
part.Touched:Connect(whenTouched)
local part = script.Parent
local debounce = false
local function whenTouched()
if not debounce then
debounce = true
local newPart = Instance.new("Part",game.Workspace)
newPart.Size = Vector3.new(1,1,1)
newPart.BrickColor = BrickColor.new("Electric blue")
newPart.Position = Vector3.new(0,0,0)
newPart.Anchored = false
debounce = false
end
end
Try that. Basically, what you have to do, is check if debounce is false. If it is, then set it to true, so it cannot fire again. Then, once you have completed your function, set it back to false, so it can fire again. Hope this helps!
local part = script.Parent
local debounce = false
local function whenTouched()
if debounce == false then
debounce = not debounce
code stuff
wait(amount of time)
debounce = false
end
end
part.Touched:Connect(whenTouched)
so what this does is it checks if debounce is false. If it is, then it executes the code, sets it to true for an amount of time and then sets it to false again
Also, @AmNotPoly I marked yours as a solution but can you also do this?
local part = script.Parent
local debounce = false
local function whenTouched()
if not debounce then
debounce = true
local newPart = Instance.new("Part",game.Workspace)
newPart.Size = Vector3.new(1,1,1)
newPart.BrickColor = BrickColor.new("Electric blue")
newPart.Position = Vector3.new(0,0,0)
newPart.Anchored = false
wait(4)
debounce = false
end
end
part.Touched:Connect(whenTouched)