I want this script to have the animation loop or keep going, it is a walking animation but it still only plays once, cant figure out why?
The script
game.Players.PlayerAdded:Connect(function (plr)
plr.CharacterAdded:Connect(function (char)
local humanoid = char:WaitForChild("Humanoid")
local track = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Walk)
track.Priority = Enum.AnimationPriority.Movement
humanoid.Running:Connect(function (speed)
if speed > 0 then
track.Looped = true
if not track.IsPlaying then
track:Play()
end
else
track:Stop()
end
end)
end)
end)
game.Players.PlayerAdded:Connect(function (plr)
plr.CharacterAdded:Connect(function (char)
local humanoid = char:WaitForChild("Humanoid")
local track = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Walk)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
humanoid.Running:Connect(function (speed)
if speed > 0 then
if not track.IsPlaying then
track:Play()
end
else
track:Stop()
end
end)
end)
end)
Script started - Server - Animations:1
Script finished loading - Server - Animations:38
Player added: WindyTundra - Server - Animations:4
Character added for: WindyTundra - Server - Animations:7
Humanoid found for: WindyTundra - Server - Animations:10
Animation instance: Walk - Server - Animations:13
Animation loaded for: WindyTundra - Server - Animations:16
Animation set to loop - Server - Animations:20
Running event fired. Speed: 0 - Server - Animations:23
Stopping animation for: WindyTundra - Server - Animations:31
Running event fired. Speed: 0 - Server - Animations:23
Stopping animation for: WindyTundra - Server - Animations:31
did that but nothing changed
game.Players.PlayerAdded:Connect(function (plr)
plr.CharacterAdded:Connect(function (char)
local humanoid = char:WaitForChild(“Humanoid”)
local track = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Walk)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
humanoid.Running:Connect(function (speed)
if speed > 0 then
if not track.IsPlaying then
track:Play()
end
else
track:Stop()
end
end)
end)
yeah it’s because the running could cause the issue we gonna try statechanged and movedirection could you give it a try
print("Script started")
game.Players.PlayerAdded:Connect(function (plr)
print("Player added: " .. plr.Name)
plr.CharacterAdded:Connect(function (char)
print("Character added for: " .. plr.Name)
local humanoid = char:WaitForChild("Humanoid")
print("Humanoid found for: " .. plr.Name)
print("Initial WalkSpeed: " .. humanoid.WalkSpeed)
humanoid.WalkSpeed = 16 -- أو أي قيمة تناسبك
print("WalkSpeed set to: " .. humanoid.WalkSpeed)
local animationInstance = game.ReplicatedStorage.Animations.Walk
print("Animation instance: " .. tostring(animationInstance))
local track = humanoid:LoadAnimation(animationInstance)
print("Animation loaded for: " .. plr.Name)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
print("Animation set to loop")
track.Stopped:Connect(function()
print("Animation stopped for: " .. plr.Name)
end)
track.Played:Connect(function()
print("Animation started playing for: " .. plr.Name)
end)
humanoid.StateChanged:Connect(function(oldState, newState)
print("Humanoid state changed from " .. tostring(oldState) .. " to " .. tostring(newState))
if newState == Enum.HumanoidStateType.Running then
local speed = humanoid.WalkSpeed
print("Current walk speed: " .. speed)
if speed > 0 then
if not track.IsPlaying then
print("Playing animation for: " .. plr.Name)
track:Play()
end
else
print("Stopping animation for: " .. plr.Name)
track:Stop()
end
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
local moveDirection = humanoid.MoveDirection
print("MoveDirection changed: " .. tostring(moveDirection))
if moveDirection.Magnitude > 0 then
if not track.IsPlaying then
print("Playing animation due to movement for: " .. plr.Name)
track:Play()
end
else
print("Stopping animation due to no movement for: " .. plr.Name)
track:Stop()
end
end)
end)
end)
print("Script finished loading")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local walkAnimation = game.ReplicatedStorage.Animations:WaitForChild("WalkAnimation")
local track = humanoid:LoadAnimation(walkAnimation)
track.Priority = Enum.AnimationPriority.Movement
-- Function to manually loop the animation
local function loopAnimation()
if track.IsPlaying then
track:Stop() -- Stop the current animation
end
track:Play() -- Play it again
end
track.Stopped:Connect(function()
loopAnimation()
end)
-- Connect to the humanoid running event
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not track.IsPlaying then
loopAnimation() -- Manually start and loop
end
else
track:Stop()
end
end)
end)
end)
Try setting it to looped before running the :Conenct function.
game.Players.PlayerAdded:Connect(function (plr)
plr.CharacterAdded:Connect(function (char)
local humanoid = char:WaitForChild("Humanoid")
local track = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Walk)
track.Priority = Enum.AnimationPriority.Movement
track.Looped = true
humanoid.Running:Connect(function (speed)
if speed > 0 then
if not track.IsPlaying then
track:Play()
end
else
track:Stop()
end
end)
end)
end)