How to play an animation when the speed of a character has reached a certain speed AND when a tool is equipped?

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 :
Capture dev forum

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 !

Of course!

This is the code for the WalkSpeed animation

regular script in ServerScriptService

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

This is the code for the tool 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:

image
(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)

Thank you very much for your help but how to combine the two scripts? Because for the moment it doesn’t work

what do you mean by combine them?

To get the two scripts you made me in one?

You can’t…

theres a server script and a local script, they can’t be put into one collective script

Ok thanks you for your help !
MiraNordlys

1 Like