Hello, I have a code so written so that if you kill a ninja (npc) the counter will go down, but for some reason the debounce doesn’t work resulting that when you kill a ninja the counter can jump from 3 down to - 16 but it varies
coroutine.resume(coroutine.create(function()
local anim = Instance.new(“Animation”)
anim.AnimationId = “rbxassetid://8016773042” --your assetID here
local track = script.Parent.Humanoid.Animator:LoadAnimation(anim)
track:Play()
end))
local Debounce = false
script.Parent.Humanoid.Died:Connect(function()
script.Parent.Torso.Touched:Connect(function(hit)
if hit:FindFirstChild(“PlayerName”) then
if Debounce == false then
Debounce = true
local player = hit.PlayerName.Value
game.ReplicatedStorage.Events.IsTemplateEnabled:FireClient(player)
end
end
end)
end)
game.ReplicatedStorage.Events.Quests.OnClientEvent:Connect(function(data)
if data == “KilledNinja” then
NumberToKillLeft = NumberToKillLeft - 1
script.Parent.Background.Info.Text = “Kill “…NumberToKillLeft…” more ninja”
if NumberToKillLeft == 0 then
coroutine.resume(coroutine.create(function()
write(script.Parent.Background.Info, "Mission complete, return to the Hokage")
end))
script.Parent.Background.ImageLabel.Image = "http://www.roblox.com/asset/?id=7882925101"
end
end
if Debounce == false then
Debounce = true
local player = hit.PlayerName.Value
game.ReplicatedStorage.Events.IsTemplateEnabled:FireClient(player)
task.wait(5)
Debounce = false
end
local Debounce = false
--NumberToKillLeft this isnt defined
--write this function isnt defined
--also add a debounce here
game.ReplicatedStorage.Events.Quests.OnClientEvent:Connect(function(data)
if data == "KilledNinja" then
if Debounce then
return
end
Debounce = true
NumberToKillLeft = NumberToKillLeft - 1
script.Parent.Background.Info.Text = "Kill "..NumberToKillLeft.." more ninja"
task.wait(10)
Debounce = false
if NumberToKillLeft == 0 then
coroutine.resume(coroutine.create(function()
write(script.Parent.Background.Info, "Mission complete, return to the Hokage")
end))
script.Parent.Background.ImageLabel.Image = "http://www.roblox.com/asset/?id=7882925101"
end
end
end)
I’ve added a debounce to the local script, try it now & I was just making sure those things were being correctly defined on your end keep the debounce change in the server script too.
Yes, it can always be shortened. Just change 10 inside the brackets. That’s the whole purpose of a debounce, to prevent a function/block of code from executing too frequently.
But that is going off in a completely different direction and that is not my problem. My problem is the debounce doesn’t work and so the event fires multiple times, I worked out it has nothing to do with that script