I have no idea how to make a 2d character move left and right when you hold D or A, ive tried using TweenService but it's confusing for me, what is the best way?
✓ ANSWER ACCEPTED
Best way to make a 2D Character move?
1 answer
✓ Accepted answer
Since it looks like you're trying to use sprites, this may be what you're looking for.
local sprite = script.Parent
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local right = 0
local left = 0
local speed = 4 --Replace with whatever number you want
UserInputService.InputBegan:Connect(function(inputObj, processed)
if (inputObj.KeyCode == Enum.KeyCode.Left or inputObj.KeyCode == Enum.KeyCode.A) then
left = 1
if (inputObj.KeyCode == Enum.KeyCode.Right or inputObj.KeyCode == Enum.KeyCode.D) then
right = 1
end
end)
UserInputService.InputEnded:Connect(function(inputObj, processed)
if (inputObj.KeyCode == Enum.KeyCode.Left or inputObj.KeyCode == Enum.KeyCode.A) then
left = 0
if (inputObj.KeyCode == Enum.KeyCode.Right or inputObj.KeyCode == Enum.KeyCode.D) then
right = 0
end
end)
RunService.RenderStepped:Connect(function(step)
sprite.Position = sprite.Position + UDim2.new(0, (right - left) * speed, 0, 0)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
What do you mean by 2D character?
An imagelabel that moves by pressing d or a
I'm currently working on a solution to your problem