I am very very very new to coding and I have 2 scripts for a tool. One of said scripts is for adding speed, and the other is for an animation. How do I add a debounce so you cant spam autoclick?
Speed script
script.Parent.Equipped:Connect(function() script.Parent.Activated:Connect(function() local Hum = script.Parent.Parent:FindFirstChild("Humanoid") Hum.WalkSpeed = Hum.WalkSpeed + 0.10 end) end)
Animation Script
script.Parent.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) animation:Play() end) end) script.Parent.Unequipped:Connect(function() animation:Stop() end)
-- 8/11/2020 0:24AM -- AswormeDorijan111 local Player = game:GetService("Players").LocalPlayer; repeat wait() until Player.Character local Char = Player.Character; local Humanoid = Char:WaitForChild("Humanoid"); local Debounce = true; local IsEquipped = false; local Cooldown = 2; -- In seconds local SpeedIncrease = 0.1; local IncreaseSpeedAfterAnim = true; -- Change this to false if you don't want to give the player speed once the animation is done local Animation = Humanoid:LoadAnimation(script.Parent:WaitForChild("Animation")); script.Parent.Equipped:Connect(function() IsEquipped = true; end) script.Parent.Activated:Connect(function() if not debounce then return end Debounce = false; Animation:Play() if IncreaseSpeedAfterAnim then Animation.Stopped:Wait() Humanoid.WalkSpeed = Humanoid.WalkSpeed + SpeedIncrease; else Humanoid.WalkSpeed = Humanoid.WalkSpeed + SpeedIncrease; end wait(Cooldown); Debounce = true; end) script.Parent.Unequipped:Connect(function() IsEquipped = false; Animation:Stop() end)
Put everything in a single Local Script and you're good to go.
Use this script:
local SpeedUpTool = script.Parent local Humanoid, Character local Debounce = false if SpeedUpTool.Parent:IsA("Model") then Character = SpeedUpTool.Parent Humanoid = Character.Humanoid elseif SpeedUpTool.Parent.Parent:IsA("Player") then Character = SpeedUpTool.Parent.Parent.Character or SpeedUpTool.Parent.Parent.CharacterAdded:Wait() Humanoid = Character.Humanoid end local Animation = Humanoid:LoadAnimation(script.Parent.Animation) SpeedUpTool.Activated:Conect(function() if not Debounce then Debounce = true Humanoid.WalkSpeed += 0.1 Animation:Play() wait(Animation.Length) Debounce = false end end)