Okay so I have a Localscript found in the player's screengui in startergui. It's basic function is simple. Move a image frame when you press a letter. Here is my problem, when the user holds down a key I want the player to keep moving until they let go of the key, how exactly would I do this?
The code:
repeat wait() until game.Players.LocalPlayer.PlayerGui
----------------------------------------------------------
-- Disable roblox's dumb stuff
----------------------------------------------------------
game.StarterGui:SetCoreGuiEnabled("All", false)
----------------------------------------------------------
-- Global Variables
----------------------------------------------------------
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local sprite = script.Parent.Player
----------------------------------------------------------
-- Movement
----------------------------------------------------------
function moveLeft()
sprite.Position = sprite.Position - UDim2.new(0.01,0,0,0)
end
function moveRight()
sprite.Position = sprite.Position + UDim2.new(0.01,0,0,0)
end
----------------------------------------------------------
-- Keyboard input
----------------------------------------------------------
Mouse.KeyDown:connect(function(Key)
if Key == "a" then
moveLeft()
end
if Key == "d" then
moveRight()
end
end)

1 comment
An easier way to do it (in my opinion) would be to simply place a bool value in the player, then control that with the KeyDown events. Now a while loop can be used to continuously check if that value is true or false.