You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am creating a local script for a weapon tool to trigger idle/walking animations after equipping the tool. -
What is the issue? Include screenshots / videos if possible!
The walk animation functions properly if I equip the tool without any prior movement, but it doesn’t work correctly while running. Instead of replacing the idle animation, the walk animation causes the idle animation to keep triggering.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I attempted to use HumanoidStateChange to detect whether the player is running, but it did not work. Currently, I am usingHumanoid.Running:Connect
to trigger the idle/walk animation.
Code:
local userInput = game:GetService(‘UserInputService’)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local IdleAnimation
local MoveAnimation
local weaponEquip = true
script.Parent.Equipped:Connect(function()
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild(“Humanoid”)
IdleAnimation = character:WaitForChild(“Humanoid”):LoadAnimation(script:WaitForChild(“IdleAnimation”))
MoveAnimation = character:WaitForChild(“Humanoid”):LoadAnimation(script:WaitForChild(“MoveAnimation”))
weaponEquip = true
IdleAnimation:Play()
humanoid.Running:Connect(function(movementSpeed)
if weaponEquip == true then
if movementSpeed > 0 then
if not MoveAnimation.IsPlaying then
IdleAnimation:Stop()
MoveAnimation:Play()
end
else
if MoveAnimation.IsPlaying then
MoveAnimation:Stop()
IdleAnimation:Play()
end
end
end
end)
end)
script.Parent.Unequipped:Connect(function()
weaponEquip = false
IdleAnimation:Stop()
MoveAnimation:Stop()
end)