Required help with script

hello devforum, i’m having a bit of trouble getting a script to work. it’s function is supposed to be a specific player in the game gets a higher animation speed for a specific animation, but it doesnt seem to work.

here is the script, can somebody help me? P.S, nightcaller helped alot.

> local player = {"Iifeform"}
> local animation = game.Workspace.Script.Animation
>    
> game.Players.PlayerAdded:connect(function(plr)
>     plr.CharacterAdded:connect(function(chr)
>         for i = 1, #player do
>             if player[i] == plr.Name then
>                 local animationTrack = chr.Humanoid:LoadAnimation(animation) 
>                 animation.AnimationId = "http://www.roblox.com/asset/?id=3269465718"
> function playAnimationForDuration(animationTrack, duration)
>     local speed = animationTrack.Length / duration
>     animationTrack:AdjustSpeed(2)
>     animationTrack:Play()
> end 
> 
> playAnimationForDuration(animationTrack, duration/2)
> 
>             end
>         end
>     end)
> end)

thank you!

And waht is wrong with it? Also some stuff seem wrong

1 Like

I’m assuming u meant to replace the 2 and put speed?

1 Like

This is wrong. Put

animation.AnimationId = "rbxassetid://3269465718"

instead of

animation.AnimationId = "http://www.roblox.com/asset/?id=3269465718"
2 Likes

Those both would word, but the second one is more og.

3 Likes

Oh ok, sorry, I thought only the rbxassetid:// worked. My bad.

1 Like

what do you mean by replace the 2 and put speed?

Why is the function in the For I loop?

I feel like it’d be better to place it before.

1 Like

First of all, you’re setting the speed to animationTrack.Length / duration but setting the animation’s speed to 2. As @iiNemo suggested, is this a mistake? Was it supposed to be animationTrack:AdjustSpeed(speed)?

Also, a better practice is to put your functions outside of the code if you want to use it in multiple places. If this is the entire code, I suggest removing the function and only keeping its contents in the script because you have a loop so it goes through it every time.

It would look something like this:

> local player = {"Iifeform"}
> local animation = game.Workspace.Script.Animation
>    
> game.Players.PlayerAdded:connect(function(plr)
>     plr.CharacterAdded:connect(function(chr)
>         for i = 1, #player do
>             if player[i] == plr.Name then
>                 local animationTrack = chr.Humanoid:LoadAnimation(animation) 
>                 animation.AnimationId = "http://www.roblox.com/asset/?id=3269465718"

>                 local speed = animationTrack.Length / duration
>                 animationTrack:AdjustSpeed(speed)
>                 animationTrack:Play()
>             end
>         end
>     end)
> end)
1 Like

I have a quick 2 questions, would I still insert the animation as a child of the script?, And would the script still be in the workspace?

I’d keep my scripts in ServerScriptService to keep everything more organized, but it’s fine to keep it in workspace as well.

1 Like