Hello everyone! I’m new on this devforum and i’m not expert at scripting. So, i’m trying to make player walk on left or right with animation. I have tried using “UserInputService” or “ContextActionService” but it wont work, the animation will stop instantly. Does anyone know?
Can you perhaps shows us the attempt you did, by posting the script you have written please?
From what I understand you’re animation is not playing constanly as long as you’re going left, it just plays once, that’s because it is not looped. There is a looped property for the Animation Track object, just set it to true, or do it manually by enabling it in the properties tab.
Heres my attempt i did.
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild(“Humanoid”)
local UserInputService = game:GetService(“UserInputService”)
local leftWalk = Instance.new(“Animation”)
leftWalk.AnimationId = “rbxassetid://2968782994”
local rightWalk = Instance.new(“Animation”)
rightWalk.AnimationId = “rbxassetid://2968782994”
hum:LoadAnimation(leftWalk)
hum:LoadAnimation(rightWalk)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.D then
print(“Going Right”)
rightWalk:Play()
elseif input.KeyCode == Enum.KeyCode.A then
print(“Going Left”)
leftWalk:Play()
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.D then
print(“Animation Stop”)
rightWalk:Stop()
elseif input.KeyCode == Enum.KeyCode.A then
print(“Animation Stop”)
leftWalk:Stop()
end
end)
I think there’s already a function that makes the player walk to a point, without using an animation. It’s called Humanoid:MoveTo.
You could just get the coordinate points of the left and right sides of the player, then use WalkTo to walk the player to those positions. Just loop the WalkTo and pass in the two positions (and perhaps add in a wait), and you get a left and right walking animation .
Did the looped property work or you found another solution?
It work property, i looped the animation and i changed the state of animation to “Action” and it work property. Thanks for the help.
Really glad I helped!