Hey guys, im trying to work out an animation using Moon Animator. Ive got the ID already but how do i make a player, that your playing as, play an animation when a proximity prompt is triggered
Hi!
First create a ProximityPrompt and place it under the rig you wish to use. Create the following within the ProximityPrompt:
Inside your script you should have this.
script.Parent.Triggered:Connect(function(Player)
local plr = Player
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local animation = script:WaitForChild("Animation") --This is your animation
local animate = animator:LoadAnimation(animation) -- This loads your animation
animate:Play() --This plays the loaded animation
end)
Thanks! it works! By the way is there also a way to set them in a custom position and not make them walk?
Simply add this line of code in your script:
script.Parent.Triggered:Connect(function(Player)
local plr = Player
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local animation = script:WaitForChild("Animation")
local animate = animator:LoadAnimation(animation)
hum.WalkSpeed = 0 -- This line here
animate:Play()
end)
Thanks! Could i also set a position for the character?
I also added a way to revert the walkspeed back to normal after your animation is done playing.
script.Parent.Triggered:Connect(function(Player)
local plr = Player
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local humrp = Player.Character:WaitForChild("HumanoidRootPart") --Add this line
local animator = hum:WaitForChild("Animator")
local animation = script:WaitForChild("Animation")
local animate = animator:LoadAnimation(animation)
hum.WalkSpeed = 0
humrp.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0,0,0) --Add this line and change the Z axis to fix them in a position in front of your NPC.
animate:Play()
task.wait()
hum.WalkSpeed = 16
end)
Hey, its not working but its giving me the error saying “HumanoidRootPart” is not a part of Workspace.Part"
Also, how exactly should you change the CFrame Value for your rig
Please send me your code so we can work on the first issue.
script.Parent.Triggered:Connect(function(Player)
local plr = Player
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local humrp = Player.Character:WaitForChild("HumanoidRootPart")
local animator = hum:WaitForChild("Animator")
local animation = script:WaitForChild("Animation")
local animate = animator:LoadAnimation(animation)
hum.WalkSpeed = 0 -- This line here
animate:Play()
humrp.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0,0,4) --Add this line and change the Z axis to fix them in a position in front of your NPC.
script.Parent.Enabled = false
wait(10)
animate:Stop()
hum.Walkspeed = 16
end)
And can you send a screenshot of the error aswell.
Where do you have your ProximityPrompt in explorer?
The part i click plays the animation
Okay, the reason for this is because I assumed you were using an NPC for your ProximityPrompt.
The reason it isn’t working for you is because a HumanoidRootPart can only belong to something that contains a Humanoid, which a part doesnt.
Okay, so what do i do now?
////
Use the scrolling bar on my last response, I added a line in there that shows you what to change.
What line? i dont see any difference.
/////
Change to
humrp.CFrame = script.Parent.Parent.CFrame * CFrame.new(0,0,4)
Wait one more thing, the whole walkspeed thing wont work anymore
Are there any errors? What is happening when you play it?