How to modify speed of modified default roblox animations?

In my game, I have a parkour system where you gain speed by running for a while. However, the walk animations are just overwritten roblox walk animations.

Here’s the script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)

	local hum = char:WaitForChild("Humanoid")
		local hrp = char:WaitForChild("HumanoidRootPart")
		local anims = char:WaitForChild("Animate")
		
		anims.walk.WalkAnim.AnimationId = "rbxassetid://74947900635575"
		anims.jump.JumpAnim.AnimationId = "rbxassetid://133746227608901"
		anims.fall.FallAnim.AnimationId = "rbxassetid://131422754475209"
end)

Because these are “animation” objects, and not “AnimationClip” objects, I can’t use the :AdjustSpeed() method on them. I don’t exactly know what to do, and I can’t seem to find another post about this specific issue in my case.

You could make your own animations, but then again you can also make a custom solution, where you do turn those animations into animationtracks and using states. There are probably implementations for this, but you could do something like:

-- CustomAnimate LocalScript

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")

-- Load Custom Animations
local walkAnim = Instance.new("Animation")
walkAnim.AnimationId = "rbxassetid://74947900635575"

local jumpAnim = Instance.new("Animation")
jumpAnim.AnimationId = "rbxassetid://133746227608901"

local fallAnim = Instance.new("Animation")
fallAnim.AnimationId = "rbxassetid://131422754475209"

-- Create Animation Tracks
local animator = humanoid:WaitForChild("Animator") or humanoid:FindFirstChildWhichIsA("Animator")
if not animator then
    animator = Instance.new("Animator")
    animator.Parent = humanoid
end

local walkTrack = animator:LoadAnimation(walkAnim)
local jumpTrack = animator:LoadAnimation(jumpAnim)
local fallTrack = animator:LoadAnimation(fallAnim)

-- Ensure animations loop appropriately
walkTrack.Looped = true
jumpTrack.Looped = false
fallTrack.Looped = false

-- Function to Adjust Animation Speed Based on Player Speed
local function adjustAnimationSpeed()
    -- Example: Base walk speed
    local baseWalkSpeed = 16 -- Default Roblox walk speed

    -- Get current speed from your parkour system
    -- Replace this with your actual method of obtaining the player's current speed
    local currentSpeed = humanoid.WalkSpeed -- Modify as needed

    -- Calculate speed multiplier
    local speedMultiplier = currentSpeed / baseWalkSpeed

    -- Clamp the multiplier to prevent extreme speeds
    speedMultiplier = math.clamp(speedMultiplier, 0.5, 2)

    -- Adjust animation playback speeds
    walkTrack.PlaybackSpeed = speedMultiplier
    jumpTrack.PlaybackSpeed = speedMultiplier
    fallTrack.PlaybackSpeed = speedMultiplier
end

-- Connect the speed adjustment to the RenderStepped event for smooth updates
RunService.RenderStepped:Connect(adjustAnimationSpeed)

-- Optional: Handle Jump and Fall States
humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        jumpTrack:Play()
    elseif newState == Enum.HumanoidStateType.Freefall then
        fallTrack:Play()
    end
end)

I am not responsible for the quality of this script :wink:

You can only adjustspeed on animation tracks rather then the animation instance. There is this built in function for the animator instance you can use by getting current animations playing.

--> Services
local players = game:GetService("Players")

--> Variables
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local animator = humanoid.Animator

---------------------------------------------------------------

local function SetAnimationSpeed(Animename: string, speed: number) : AnimationTrack
	for index : number, animation : AnimationTrack in animator:GetPlayingAnimationTracks() do
		if animation.Length > 0 and string.match(tostring(animation), Animename) then
			animation:AdjustSpeed(speed)
			return animation
		end
	end
end

--> Events
humanoid.Running:Connect(function(speed: number)
	local animation = SetAnimationSpeed("RunAnim", 5) -- Animation Name and speed to set the animation speed
	print(speed, animation)
end)

Note that you can do more events other than then the humanoid running like humanoid states.

1 Like

Okay, i’ll make sure to try out this method, and tell you what happens.