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:

game.ReplicatedStorage.ShankIdle.OnServerEvent:Connect(function(player)
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    local sound1 = Instance.new("Sound", hum.Parent)
    sound1.SoundId = "rbxassetid://3688156764"
    idleloader:Play()
    sound1:Play()
    print("Equipped")
end)

game.ReplicatedStorage.Shank.OnServerEvent:Connect(function(player)
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    idleloader:Stop()

    local anime = Instance.new("Animation")
    anime.AnimationId = "rbxassetid://3789143130"
    local hum = player.Character.Humanoid
    local loader = hum:LoadAnimation(anime)
    loader:Play()
    wait(0.24)
    idleloader:Play()
    print("Shanked")
    wait(0.5)
end)
game.ReplicatedStorage.QuitShankIdle.OnServerEvent:Connect(function(player)
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    idleloader:Stop()
    print("Unequipped")
end)

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

local db = false


game.ReplicatedStorage.ShankIdle.OnServerEvent:Connect(function(player)
  if not db then
db = true
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    local sound1 = Instance.new("Sound", hum.Parent)
    sound1.SoundId = "rbxassetid://3688156764"
    idleloader:Play()
    sound1:Play()
    print("Equipped")
wait (1) -- this can be however u want
db = false
end)

game.ReplicatedStorage.Shank.OnServerEvent:Connect(function(player)
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    idleloader:Stop()

    local anime = Instance.new("Animation")
    anime.AnimationId = "rbxassetid://3789143130"
    local hum = player.Character.Humanoid
    local loader = hum:LoadAnimation(anime)
    loader:Play()
    wait(0.24)
    idleloader:Play()
    print("Shanked")
    wait(0.5)
end)
game.ReplicatedStorage.QuitShankIdle.OnServerEvent:Connect(function(player)
    local idleanime = Instance.new("Animation")
    idleanime.AnimationId = "rbxassetid://3789083756"
    local hum = player.Character.Humanoid
    local idleloader = hum:LoadAnimation(idleanime)
    idleloader:Stop()
    print("Unequipped")
end)
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