Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable to make an animation play when triggering a ProximityPrompt?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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?

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. Officer_Striker 2 — 3y
0
@Officer_Striker is there any errors? MarkedTomato 810 — 3y
0
@MarkedTomato no errors Officer_Striker 2 — 3y
0
Is it a LocalScript? MarkedTomato 810 — 3y
View all comments (3 more)
0
@MarkedTomato yeah, its a LocalScript located in the StarterPlayerScripts Officer_Striker 2 — 3y
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 MarkedTomato 810 — 3y
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? Officer_Striker 2 — 3y
Ad

Answer this question