**So im making a sliding script but i want to stop players from spamming the sliding option
i'd like to make the player wait 5 seconds before they can slide again**
local UIS = game:GetService("UserInputService") local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local slideAnim = Instance.new("Animation") slideAnim.AnimationId = "rbxassetid://9618771941" local canslide = false local keybind = Enum.KeyCode.C local topspeed = 25 character.Humanoid.Running:Connect(function(speed) if speed > topspeed then canslide = true else if speed < topspeed then canslide = false end end end) humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function() if humanoid.FloorMaterial == Enum.Material.Air then canslide = false else if humanoid.FloorMaterial ~= Enum.Material.Air then canslide = true end end UIS.InputBegan:Connect(function(input,gameprocessed) if gameprocessed then return end if not canslide then return end if input.KeyCode == keybind then canslide = false local playAnim = character.Humanoid:LoadAnimation(slideAnim) playAnim:Play() local slide = Instance.new("BodyVelocity") slide.MaxForce = Vector3.new(1,0,1) * 30000 slide.Velocity = character.HumanoidRootPart.CFrame.lookVector * 100 slide.Parent = character.HumanoidRootPart for count = 1, 8 do wait(0.15) slide.Velocity*= 0.7 end playAnim:Stop() slide:Destroy() canslide = true end end) end)
Your script should use debounce. Here is an example - try implementing this into your script.
local Debounce = false function Example() if Debounce == true then return end print("Hello there") Debounce = true wait(1) Debounce = false end
If a function is fired while Debounce = true, then the function will immediately end before it can do anything.
should it be like this? explain please since im new to scripting so i dont understand
01 local UIS = game:GetService("UserInputService") 02 local character = script.Parent 03 local humanoid = character:WaitForChild("Humanoid") 04 local slideAnim = Instance.new("Animation") 05 slideAnim.AnimationId = "rbxassetid://9618771941" 06 local debounce = false 07 function example() if debounce == true then return end print ("hello") debounce = true wait(5) debounce = false end 08 local canslide = false 09 local keybind = Enum.KeyCode.C 10 11 12 local topspeed = 25 13 character.Humanoid.Running:Connect(function(speed) 14 if speed > topspeed then 15 canslide = true 16 else if speed < topspeed then 17 canslide = false 18 19 end 20 end 21 end) 22 humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function() 23 if humanoid.FloorMaterial == Enum.Material.Air then 24 canslide = false 25 else if humanoid.FloorMaterial ~= Enum.Material.Air then 26 canslide = true 27 28 29 end 30 end 31 UIS.InputBegan:Connect(function(input,gameprocessed) 32 if gameprocessed then return end 33 if not canslide then return end 34 if input.KeyCode == keybind then 35 canslide = false 36 37 local playAnim = character.Humanoid:LoadAnimation(slideAnim) 38 39 playAnim:Play() 40 41 local slide = Instance.new("BodyVelocity") 42 slide.MaxForce = Vector3.new(1,0,1) * 30000 43 slide.Velocity = character.HumanoidRootPart.CFrame.lookVector * 100 44 slide.Parent = character.HumanoidRootPart 45 46 for count = 1, 8 do 47 wait(0.15) 48 slide.Velocity*= 0.7 49 end 50 playAnim:Stop() 51 slide:Destroy() 52 canslide = true 53 end 54 end) 55 end)