Hello! I’m making a silly little banana tool, however the debounce is failing to work and is making the whole ordeal annoying. I have tried to fix it, my friend has tried to fix it. Heck I even used chatgpt, so if you have even the slightest idea, I would be delighted.
Here is my script:
wait(1)
local banana = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local ragdollRemote = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("Ragdoll")
local debounce = false
function onTouched(part)
local character = part:FindFirstAncestorWhichIsA("Model")
local humanoid = character and character:FindFirstChild("Humanoid")
if humanoid and not debounce then
debounce = true
banana.Scream:Play()
banana.SlipSound:Play()
task.delay(3.5, function()
debounce = false
end)
ragdollRemote:Fire(character, 3)
end
end
banana.Touched:Connect(onTouched)
local banana = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local ragdollRemote = replicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("Ragdoll")
local debounce:boolean = false
function onTouched(part:BasePart):()
if debounce==true then return end
local character:Instance = part.Parent
if not character:IsA("Model") then return end
local humanoid:Humanoid? = character:FindFirstChild("Humanoid")
if humanoid==nil then return end
debounce = true
banana.Scream:Play()
banana.SlipSound:Play()
ragdollRemote:Fire(character, 3)
task.wait(3.5)
debounce = false
end
banana.Touched:Connect(onTouched)
Yarik thank you for your help again! However now instead of playing at random intervals. The script always plays twice with about a 10 millisecond interval. This is significant progress but I am still so confused.
Still doubles on the function. Another thing I’ve noted is that everytime the debris is removed the game freezes for about a second. Maybe I’m spawning this twice somehow? If so here’s the script for that.
local tool = script.Parent
local handle = tool.Handle
local placesound = tool.PlaceSound
local spawncooldown = 10
local debounce = true
local function spawn()
debounce = false
local part = handle:Clone()
placesound:Play()
part.Parent = game.Workspace
part.Position = handle.Position
part.CanCollide = true
part.Orientation = Vector3.new(0,0,0)
game.Debris:AddItem(part,10)
end
tool.Activated:Connect(function()
if debounce == true then
spawn()
wait(spawncooldown)
debounce = true
end
end)
May not be your problem here but, I like to always set the flag right way.
just to be sure nothing else get’s by while doing other things.
if debounce then debounce = flase
As I’ve just tested setting the flag before hand doesn’t fix the issue. Return ends get in the way and like I did before, it just gave me a chance for the script to play out but still multiple times