local Character = script.Parent
local maxSpeed = 20
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local slideTweenInfo = TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local isSliding = false
local slideKeyCode = Enum.KeyCode.LeftControl
function slide()
local humanoid = Character:FindFirstChild("Humanoid")
local goal = {}
if humanoid then
if isSliding == false then
goal.CameraOffset = Vector3.new(0,0,0)
maxSpeed = 20
local slideTween = TweenService:Create(humanoid,slideTweenInfo,goal)
Character:FindFirstChild("Head").CanCollide = true
slideTween:Play()
elseif isSliding == true then
goal.CameraOffset = Vector3.new(0,-2,0)
maxSpeed = 40
Character:FindFirstChild("Head").CanCollide = false
local slideTween = TweenService:Create(humanoid,slideTweenInfo,goal)
slideTween:Play()
end
end
end
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == slideKeyCode and isSliding == false then
isSliding = true
slide()
end
end
end)
UserInputService.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == slideKeyCode and isSliding == true then
isSliding = false
slide()
end
end
end)```
My code is listed above. I have max speed set for separate functions. How would I go about adding a cooldown for this? I've tried several ways but I'm stuck.
I don't entirely know what to tag this, so apologies if It seems weird...
#Slide system cooldown
9 messages · Page 1 of 1 (latest)
To add a cooldown to the slide function, you can use a timer object to track the elapsed time between slide events. Here is an example of how you can modify the code to implement a cooldown:
@weak jasper
Apologies, but it does not seem to be working.
Sorry I could not help.
@weak jasper Don't know if you heard of debounce but
local Character = script.Parent
local maxSpeed = 20
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local slideTweenInfo = TweenInfo.new(.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local isSliding = false
local slideKeyCode = Enum.KeyCode.LeftControl
local debounce = false -- Debounce
function slide()
local humanoid = Character:FindFirstChild("Humanoid")
local goal = {}
if humanoid then
if isSliding == false then
goal.CameraOffset = Vector3.new(0,0,0)
maxSpeed = 20
local slideTween = TweenService:Create(humanoid,slideTweenInfo,goal)
Character:FindFirstChild("Head").CanCollide = true
slideTween:Play()
elseif isSliding == true then
goal.CameraOffset = Vector3.new(0,-2,0)
maxSpeed = 40
Character:FindFirstChild("Head").CanCollide = false
local slideTween = TweenService:Create(humanoid,slideTweenInfo,goal)
slideTween:Play()
end
end
end
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == slideKeyCode and isSliding == false and not debounce then --Checking if debounce is false
isSliding = true
slide()
end
end
end)
UserInputService.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == slideKeyCode and isSliding == true and not debounce then --Checking if debounce is false
debounce = true -- They ended sliding so change it to true so ^^ doesnt run
isSliding = false
slide()
wait(2) -- after firing the function wait 2 seconds
debounce = false -- and change the debounce to false again
end
end
end)
i have tested this script on my own pc