I’m trying to get an animation to play on an R6 player, I followed a tutorial but the animation does not play but the rest of the things in the script work, anybody know who to fix this? I have tried using other animations than the one they use in the video.
Script:
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 35
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://6712401177'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
end
end)
Humanoid:LoadAnimation() is a deprecated(removed) use the Animator instead (Humanoid:WaitForChild("Animator"):LoadAnimation([Animation Instance])) .
In your case, the animation instance would be the variable named Anim.
I looked at the animation you’re trying to use, it’s uploaded by someone else. Assuming the account you’re using is the one you’re using to communicate here then, you have to have uploaded the animation yourself. You’re unable to use other users animations unless it’s uploaded by ROBLOX themselves.
You can try preloading the animation, instead of making a new animation every time the player starts running. Something like:
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://YOUR_ID'
local PlayAnim = Character.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 35
PlayAnim:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
end
end)