Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can we add a delay on this script from stopping it from running too fast?

Asked by 5 years ago

So we have a Knife script, That plays an animation when you click. But you can spam click the knife, and it just glitches it out? How could we add a delay or debounce in this to stop the animation from running too fast? Thanks. Server Script:

01game.ReplicatedStorage.ShankIdle.OnServerEvent:Connect(function(player)
02    local idleanime = Instance.new("Animation")
03    idleanime.AnimationId = "rbxassetid://3789083756"
04    local hum = player.Character.Humanoid
05    local idleloader = hum:LoadAnimation(idleanime)
06    local sound1 = Instance.new("Sound", hum.Parent)
07    sound1.SoundId = "rbxassetid://3688156764"
08    idleloader:Play()
09    sound1:Play()
10    print("Equipped")
11end)
12 
13game.ReplicatedStorage.Shank.OnServerEvent:Connect(function(player)
14    local idleanime = Instance.new("Animation")
15    idleanime.AnimationId = "rbxassetid://3789083756"
View all 37 lines...

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

99% sure this is a troll :/ anyway

Add a debounce dude its really easy

01local db = false
02 
03 
04game.ReplicatedStorage.ShankIdle.OnServerEvent:Connect(function(player)
05  if not db then
06db = true
07    local idleanime = Instance.new("Animation")
08    idleanime.AnimationId = "rbxassetid://3789083756"
09    local hum = player.Character.Humanoid
10    local idleloader = hum:LoadAnimation(idleanime)
11    local sound1 = Instance.new("Sound", hum.Parent)
12    sound1.SoundId = "rbxassetid://3688156764"
13    idleloader:Play()
14    sound1:Play()
15    print("Equipped")
View all 44 lines...
0
I already did a debounce. It didn't work, Oh and your's didn't work either. Mrmonkeyman120 65 — 5y
0
Wait, I figured it out, I put the debounce in the wrong area, Thanks. Mrmonkeyman120 65 — 5y
Ad

Answer this question