Hello,
I’m trying to have an animation play whenever a character is idle/moving with a tool equipped. However, the animation doesn’t loop; it only plays once and then back to the default idle/moving animations.
I have set the idle animation priority to idle, and the movement animations to action. I have looked at dev hub to try and solve this. . . I’ve either missed something on the dev hub, or just messed up in the code. I would appreciate if someone could answer this soon
local humanoid = nil
local char = nil
local player = nil
local rootPart = nil
local mouse = nil
local idleAnim = nil
local forwardAnim = nil
local LeftAnim = nil
local RightAnim = nil
local wPressed = false
local sPressed = false
local aPressed = false
local dPressed = false
local spPressed = false
local equipped = false
local flying = false
local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function()
humanoid = script.Parent.Parent.Humanoid
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
char = script.Parent.Parent
idleAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("IdleAnim"))
forwardAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
RightAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
LeftAnim = char:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("ForwardAnim"))
rootPart = script.Parent.Parent.HumanoidRootPart
mouse = player:GetMouse()
equipped = true
print("anim to be played")
idleAnim:Play()
end)
script.Parent.Unequipped:Connect(function()
equipped = false
idleAnim:Stop()
print("anim stopped")
forwardAnim:Stop()
LeftAnim:Stop()
RightAnim:Stop()
end)
uis.InputBegan:Connect(function(key, chat)
if equipped then
if chat then return end
if key.KeyCode == Enum.KeyCode.W and equipped == true then
wPressed = true
forwardAnim:Play()
elseif key.KeyCode == Enum.KeyCode.S and equipped == true then
sPressed = true
forwardAnim:Play()
elseif key.KeyCode == Enum.KeyCode.A and equipped == true then
aPressed = true
LeftAnim:Play()
elseif key.KeyCode == Enum.KeyCode.D and equipped == true then
dPressed = true
RightAnim:Play()
end
end
end)
uis.InputEnded:Connect(function(key, chat)
if chat then return end
if key.KeyCode == Enum.KeyCode.W then
wPressed = false
forwardAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.S then
sPressed = false
forwardAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.A then
aPressed = false
LeftAnim:Stop()
elseif key.KeyCode == Enum.KeyCode.D then
dPressed = false
RightAnim:Stop()
end
end)
YouTube vid showcasing issue above