I want my skydiving animation to play when the player jumps out of a helicopter but I don’t know how to start the animation when the player touches the part. I have a script to play it but that just plays it when they spawn, any solutions?
So what I would do is first make a part then add a Script into it, then make a touched function EX:
script.Parent.Touched:Connect(function(plr)
if plr:FindFirstChild(-- The name of the script in StarterCharacterScripts) then
plr.Parent.ScriptName.BoolValueName.Value = true
end
Now insert a script into StarterCharacterScripts then a BoolValue into the script and name it Anything you want. Then insert an animation into the script and put ur animation ID into the AnimationID part.
After you do that type this into the script
if script.BoolValueName.Value == true then
local animation = script.Parent.Humanoid:LoadAnimation(script.AnimationName)
animation:Play()
end
ps remember to change the “AnimationName” and stuff to the name of the instances
How do I make a BoolValue and insert the animation?
Click the little plus by the script and search BoolValue and Animation
make the if plr:FindFirstChild(“AnimationScript”) not if plr:FindFirstChild(AnimationScript)
and make the BoolValue name BoolValueName instead of Value
Ok, I did all of that but it still won’t work. Should I make the part visible?
Delete everything in the scripts.
Make the script in the part say
script.Parent.Touched:Connect(function(plr)
if plr:FindFirstChild("AnimationScript") then
plr.Parent.AnimationScript.Value.Value = true
end
end)
make the script in startercharacterscripts say
if script:FindFirstChild("Value").Value == true then
local anim = script.Parent.Humanoid:LoadAnimation(script.Animation)
anim:Play()
end
It still doesn’t work
Studio hates me!
Did you put the animation id in the animation?
Yep, I did that. Is there a minimum part size and I made the part to small? Or does it not work because the part is invisible? Do I need an AnimationController?
note humanoid:LoadAnimation() is deprecated
What does deprecated mean? How do I fix it?
Deprecated means that the code is no longer supported, so it may break in the future and you should not use it. Instead they replaced it with Animator:LoadAnimation
.
An animator is in every player’s humanoid. When a player touches a part, it won’t return the player who touched it, it returns the part that touches it, which could be the torso, hand, or whatever. Meaning the parent of whatever touched it is where the humanoid is, which is where the animator is.
So you can do
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild('Humanoid')
if humanoid then
local animator = humanoid:FindFirstChild('Animator')
if animator then
animator:LoadAnimation(script.Parent.AnimationName)
end
end
Replace AnimationName with the animations name, and make sure you add the animation inside of the part because part.Parent
The code might be messy since I did not use studio to write it and I’m used to autofill…
Also this code did not work because it only checked once but the method below is better
Code only runs once so by the time the game starts this code would stop running. Instead do this:
script.BoolValueName:GetPropertyChangedSignal("Value"):Connect(function()
if script.BoolValueName.Value == true then
local animation = script.Parent.Humanoid:LoadAnimation(script.AnimationName)
animation:Play()
end
end)
That way it will run every time the value changes/
Ok, changed it to that but can’t test rn.
This still doesn’t work, I just tested it. What else can I try?
Did you replace BoolValueName
with the name of the bool value and replace AnimationName
with the name of the animation?