I am trying to make a 2d game using sprites.
To move your character, you need to hold A or D…
But the problem is, you do not have to. You simply press a button (I do not want that by the way) and it moves by itself…
And that can cause problems, such as pressing two times, you get bonus speed and shakey screen…
local Player = game.Players.LocalPlayer
local UIS = game:GetService('UserInputService')
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
while input do
task.wait(0.03)
script.Parent.Position -= UDim2.new(0.003, 0, 0, 0)
script.Parent.Parent.Position += UDim2.new(0.003*4, 0, 0, 0)
end
elseif input.KeyCode == Enum.KeyCode.D then
while input do
task.wait(0.030)
script.Parent.Position += UDim2.new(0.003, 0, 0, 0)
script.Parent.Parent.Position -= UDim2.new(0.003*4, 0, 0, 0)
end
elseif input.KeyCode == Enum.KeyCode.W then
for i = 1, 10 do
task.wait(0.030)
script.Parent.Position += UDim2.new(0, 0, -0.006, 0)
end
for i = 1, 10 do
task.wait(0.030)
script.Parent.Position -= UDim2.new(0, 0, -0.006, 0)
end
end
end)
So how can I actually detect if the player is holding a/the button?