So, this is an extension to another post I made yesterday. I completely re-did my script and it works! But I have to spam click WASD in order to move. How do I make it so when I hold down a key, the frame moves.
Here’s my new script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local debounce = false
--D
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.D then
if debounce == false then
debounce = true
script.Parent.Position = script.Parent.Position + UDim2.new(0.01,0,0)
end
wait(0.5)
debounce = false
end
end)
--W
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
if debounce == false then
debounce = true
script.Parent.Position = script.Parent.Position - UDim2.new(0,0,0.01)
end
wait(0.5)
debounce = false
end
end)
--A
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.A then
if debounce == false then
debounce = true
script.Parent.Position = script.Parent.Position - UDim2.new(0.01,0,0)
end
wait(0.5)
debounce = false
end
end)
--S
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.S then
if debounce == false then
debounce = true
script.Parent.Position = script.Parent.Position + UDim2.new(0,0,0.01)
end
wait(0.5)
debounce = false
end
end)