Good evening to all! I would like to know how to play an animation when the speed of a character has reached a certain speed AND when a tool is equipped. To be clear, I would like my Paragliding model to come alive when the user has equipped the tool and when the character runs.
Here the image of my tool with the script that allows to fly paragliding :
Thank you in advance for your help!
Best regards,
MiraNordlys
You can run a check everytime their WalkSpeed property changes. If it’s above or equal to a certain number, play the animation, if not, stop playing it.
For the tool equip, just do a simple script that loads the animation when they equip the tool. If you would like, I could write something along the lines of this for you.
First, thank you for your very quick response! Not being an excelent in the handling of scripts, it will help me a lot if you could write a little code! Thank you in advance !
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
local animation = script.Animation
local loadAnim = hum:LoadAnimation(animation)
hum.WalkSpeed.Changed:Connect(function(newSpeed)
if newSpeed >= 18 then --(change this to the speed you want the animation to start at)
loadAnim:Play()
else
loadAnim:Stop()
end)
end)
end)
Something like this should work for the WalkSpeed animation
local script inside the tool, you also need an Animation inside the tool.
-- Waits for the child of the specified parent
local function WaitForChild(parent, childName)
while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
return parent[childName]
end
local Tool = script.Parent
local Animations = {}
local MyHumanoid
local MyCharacter
local function PlayAnimation(animationName)
if Animations[animationName] then
Animations[animationName]:Play()
end
end
local function StopAnimation(animationName)
if Animations[animationName] then
Animations[animationName]:Stop()
end
end
function OnEquipped(mouse)
MyCharacter = Tool.Parent
MyHumanoid = WaitForChild(MyCharacter, 'Humanoid')
if MyHumanoid then
Animations['IdleAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'Animation'))
end
PlayAnimation('IdleAnim')
end
function OnUnequipped()
for animName, _ in pairs(Animations) do
StopAnimation(animName)
end
end
Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)
Screenshot of what your tool should look like:
(of course you will have different parts to my tool, but this is just an example of a tool I have with an equip animation)