I’m basically looking to find out how to make it so when my R6 character is walking, it gradually gets faster.
I am very new to scripting and have little knowledge and I am starting from 0.
I don’t want to have a shift keybind function to run or anything, just looking to find out how to make it so my character starts walking slow (e…g. 1 walkspeed) and gets to something faster (e.g. 18 walkspeed) within maybe 0.4 seconds
I would also like it to be able to make the walking animation start off very slow and then gradually increase to the correct animationspeed in accordance to the walkspeed…
I really don’t want to give out scripts. But anyway, try to understand what im trying to do, this script is in startercharacterscripts.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local MIN_SPEED = 10
local MAX_SPEED = 20
local ACCELERATION = 20 -- Speed units per second
local DECELERATION = 40 -- Speed units per second
local targetSpeed = MIN_SPEED
local currentSpeed = MIN_SPEED
local function updateSpeed(dt)
local moveDirection = humanoid.MoveDirection
if moveDirection.Magnitude > 0 then
targetSpeed = MAX_SPEED
else
targetSpeed = MIN_SPEED
end
if currentSpeed < targetSpeed then
currentSpeed = math.min(currentSpeed + ACCELERATION * dt, targetSpeed)
elseif currentSpeed > targetSpeed then
currentSpeed = math.max(currentSpeed - DECELERATION * dt, targetSpeed)
end
humanoid.WalkSpeed = currentSpeed
end
RunService.Heartbeat:Connect(updateSpeed)
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
humanoid = character:WaitForChild("Humanoid")
currentSpeed = MIN_SPEED
humanoid.WalkSpeed = MIN_SPEED
end)
I appreciate this very much. Extremely helpful.
Do you have any advice on how to make the animation speed start slow and then gradually get fast? Is there some sort of instance I can use?
What I like to do for that is increase the animation speed based on a ratio, so, for example
local animationTrack = [[Your Animation Track]]
local Humanoid = [[Humanoid of the player character]]
local walkSpeed = [[The walkspeed on which the animations looks normal]]
local animSpeedRatio = (animationTrack.Speed/walkSpeed)
local runConnection = nil
runConnection = game:GetService("RunService").Heartbeat:Connect(function()
if Humanoid.Parent == nil or Humanoid.Health <= 0 then
--The character has died or no longer exists, disconnect
runConnection:Disconnect()
return
end
if animationTrack.IsPlaying then
--Only adjust the speed when animation is playing
animationTrack:AdjustSpeed(animSpeedRatio * Humanoid.WalkSpeed)
end
end)
While you can just slap it on your animation and it’ll work, this is supposed to act as a blueprint to how you can modify the animation speed with the walkspeed