Play animation via script

I have this script but it does not play animation.(but prints successful)
Ive tried binding local script to the same pprompt but it didnt work either.
Is tgere any way to fix this? I need to keep a normal script too as it includes some functions l neeed (such as changing object properities etc)… help please

function ButtonClicked(Player)
	route.Button.ProximityPrompt.Enabled = false
	local shockAnimation = script.Animation
	shockAnimation.AnimationId = "http://www.roblox.com/asset/?id=11531168774"
	local char = Player.Character or Player.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	local loadanim = humanoid:LoadAnimation(shockAnimation)
	print("successful")
end
workspace.Button.ProximityPrompt.Triggered:Connect(ButtonClicked)

change this too…

shockAnimation.AnimationId = "rbxassetid://11531168774"
1 Like
loadanim:Play()

This will play the animation. Right now, you’ve just loaded it and nothing else.

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://11531168774"
workspace.Button.ProximityPrompt.Triggered:Connect(function(player)
	route.Button.ProximityPrompt.Enabled = false
	local track = player.Character.Humanoid.Animator:LoadAnimation(anim)
	track:Play()
	-- Did you want to reenable the prompt later?
end)
2 Likes

this is the better solution. As I was not looking as how the animation was played.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.