Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to make an animation play when triggering a ProximityPrompt?

Whenever I trigger a ProximityPrompt, the following error pops up in the output: "Unable to cast value to Object - Client - LocalScript:5" The LocalScript is located in StarterPlayerScripts and the following script is what is in it:

local Animation = script.AnimationOpen
local Proxy = workspace.MainRoomDoor.MainRoom

Proxy.Triggered:Connect(function(Player)
	local Anim = Player.Character:WaitForChild("Humanoid"):LoadAnimation(5915776835) 
	Anim:Play()
end)

1 answer

I rarely use animations so this should help you

local Animation = script.AnimationOpen
local Proxy = workspace.MainRoomDoor.MainRoom

Proxy.Triggered:Connect(function(Player)
   local humanoid = Player.Character.Humanoid
   local Animator = humanoid.Animator

   local anim = Instance.new("Animation")
   anim.AnimationId = "rbxassetid://5915776835"
 
   local animationTrack = Animator:LoadAnimation(anim)
   animationTrack.Priority = Enum.AnimationPriority.Action
   animationTrack:Play()
end)

-----EXPLANATION-----
--[[
When prompt is triggered the following function will run.
A variable for the humanoid and the Animator.
Creating a new instance which is an Animation.
Changing the AnimationId of the Animation.

Loading the animation to the Animator.
Changing the priority to Action. Action is the highest priority so it will override all other animations.
Then it will play the Animation.
]]

Also, what is the Animation variable in your script?

7 comments

0

The Animation variable was from earlier when I was making adjustments, so its nothing functional, just forgot it was there, besides its still not triggering the animation, ill try going off the link you send.

0

@Officer_Striker is there any errors?

0

@MarkedTomato no errors

0

Is it a LocalScript?

0

@MarkedTomato yeah, its a LocalScript located in the StarterPlayerScripts

0

https://devforum.roblox.com/t/unable-to-cast-value-to-object/817248 this guy did exactly what you tried to do. Check it out

0

@MarkedTomato, I checked it out, went to the answer and modified the script a bit to it, still doesn't seem to be working and no script errors, or output errors popping up?

This discussion is preserved as it was. New answers, comments, and votes are closed.