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