I want the running animation to play only when the player is running and has a tool equipped
I looked for tutorials on youtube and developer hub, but none of the scripts worked or they were glitching out
local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animate = Character:WaitForChild("Animate")
Sword.Equipped:Connect(function()
Animate.run.RunAnim.AnimationId = "rbxassetid://15144877556"
end)
Sword.Unequipped:Connect(function()
Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"
end)
The animation id changes, but it doesn’t change the animation in-game.
local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local runAnimationId = "rbxassetid://15144877556"
local isRunning = false
local function playRunningAnimation()
Animate.run.RunAnim.AnimationId = runAnimationId
end
local function stopRunningAnimation()
Animate.run.RunAnim.AnimationId = ""
end
local function checkRunning()
if Humanoid:GetState() == Enum.HumanoidStateType.Running then
if not isRunning then
isRunning = true
playRunningAnimation()
end
else
if isRunning then
isRunning = false
stopRunningAnimation()
end
end
end
Sword.Equipped:Connect(function()
checkRunning()
end)
Sword.Unequipped:Connect(function()
if isRunning then
isRunning = false
stopRunningAnimation()
end
end)
Character:WaitForChild("Humanoid").Running:Connect(checkRunning)
I tried the code,
animation played when the tool wasnt equipped.
I added a line of code that detects if the tool is equipped, but it doesn’t update when you equip the tool while running.
local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local runAnimationId = "rbxassetid://15144877556"
local isRunning = false
local function playRunningAnimation()
Animate.run.RunAnim.AnimationId = runAnimationId
end
local function stopRunningAnimation()
Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"
end
local function checkRunning()
if Humanoid:GetState() == Enum.HumanoidStateType.Running then
if not isRunning then
if Character:WaitForChild("Sword") then -- this is what i added
isRunning = true
playRunningAnimation()
end
end
else
if isRunning then
if Character:WaitForChild("Sword") then -- this is what i added
isRunning = false
stopRunningAnimation()
end
end
end
end
Sword.Equipped:Connect(function()
checkRunning()
end)
Sword.Unequipped:Connect(function()
if isRunning then
isRunning = false
stopRunningAnimation()
end
end)
Character:WaitForChild("Humanoid").Running:Connect(checkRunning)