My animation speed change script isn't working

I have this script that changes an animations speed with sound loudness, and it does not work. Any help? Here is the script

local Player = game.Players.LocalPlayer

local Character = Player.Character

local Humanoid = Character:WaitForChild("Humanoid")

Idle = Humanoid:LoadAnimation(script.Dance)

Idle.Looped = true

Idle:Play()

while true do

Idle.Speed = math.clamp(game.Workspace.KohlAudioVisualizer.Sound.PlaybackLoudness/700, 0.2, 0.5)

end
1 Like

Wait what lol,you dont need a script for changing animation speed you can add a BoolValue for that(easy Tutorial for that about Animating NPCS

Watch the full video to understand

2 Likes

You do realize that the npc has a script that uses AdjustSpeed and the boolvalue is just to make it easier to set right?

The script Shea Used:

--Variables--
local set = script.Settings
local sp = set.Speed
local enabled = set.Enabled
local hum = script.Parent:WaitForChild("Humanoid")
if hum then
	print("Success")
else
	print("No Humanoid")
end
local humanim = hum:LoadAnimation(script:FindFirstChildOfClass("Animation"))

--Playing Animation--
if enabled.Value == true then
	humanim:Play()
	humanim.Looped = true
	humanim:AdjustSpeed(sp.Value) -- This is what gets the boolvalue value and sets the speed with. 
end

Edit: @Pooglies
You should be using AdjustSpeed: https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/AdjustSpeed

4 Likes

learn how to use Values for speed

1 Like

What does that mean? You cant just insert a Intvalue into a character and expect it to slow down and go faster based on music.

The person wants the speed to be adjusted by the music and PlaybackLoudness. You need AdjustSpeed in order to do this. The tutorial you see just makes it easier by having the script already made which looks for the values and uses them as settings to change it to fit your need. What he wants to do is make it speed up and slow down based on the loudness of the music thats being played.

2 Likes

Woah bro, slow down.
You can’t do that, unless it is from the default animation script.
Do know that making int values is inefficient as well

However, here is a section of @Pooglies code I edited.
Change:

while true do Idle.Speed = math.clamp(game.Workspace.KohlAudioVisualizer.Sound.PlaybackLoudness/700, 0.2, 0.5) end

to:

game.Workspace.KohlAudioVisualizer.Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()

Idle:AdjustSpeed(math.clamp(game.Workspace.KohlAudioVisualizer.Sound.PlaybackLoudness/700, 0.2, 0.5))

end)
3 Likes

Greetings from 2021. This is the top search result when you look for changing character animation speed.

Looks like there was some confusion about what people meant up there. Maybe the current answer wasn’t valid back then, but
image

So:

-- Original poster had:
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

-- so get the config value to base the adjustment on:
local scaleDampening = Character:WaitForChild("Animate"):WaitForChild("ScaleDampeningPercent")
local defaultDampening = scaleDampening.Value

-- then where you want to change the speed:
local speedFactor = 0.5 -- half animation speed
scaleDampening.Value = defaultDampening / speedFactor

I’m pretty sure if I was trying to do what OP was trying to do, I would maybe temporarily change the character’s idle animation set to the custom dance animation.
More likely, just add a new dance animation to the animation sets as a custom emote and set the emote.

More info in this thread:

1 Like