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:
01 | repeat wait() until game.Players.LocalPlayer.PlayerGui |
02 | ---------------------------------------------------------- |
03 | -- Disable roblox's dumb stuff |
04 | ---------------------------------------------------------- |
05 | game.StarterGui:SetCoreGuiEnabled( "All" , false ) |
06 | ---------------------------------------------------------- |
07 | -- Global Variables |
08 | ---------------------------------------------------------- |
09 | local Player = game.Players.LocalPlayer |
10 | local Mouse = Player:GetMouse() |
11 | local sprite = script.Parent.Player |
12 | ---------------------------------------------------------- |
13 | -- Movement |
14 | ---------------------------------------------------------- |
15 | function moveLeft() |
Here's how I would write this code:
01 | repeat wait() until game.Players.LocalPlayer.PlayerGui |
02 | ---------------------------------------------------------- |
03 | -- Disable roblox's dumb stuff |
04 | ---------------------------------------------------------- |
05 | game.StarterGui:SetCoreGuiEnabled( "All" , false ) |
06 | ---------------------------------------------------------- |
07 | -- Global Variables |
08 | ---------------------------------------------------------- |
09 | local Player = game.Players.LocalPlayer |
10 | local Mouse = Player:GetMouse() |
11 | local sprite = script.Parent.Player |
12 |
13 | local keysDown = { } |
14 | ---------------------------------------------------------- |
15 | -- Movement |
This is a variant of what Perci1 suggested you do.
I'd use a 'while' loop and some static boolean values to make sure that it's doing what it should be doing at a given time.
01 | isGoingLeft = false |
02 | isGoingRight = false |
03 |
04 | Mouse.KeyDown:connect( function (Key) |
05 | if Key:lower() = = "a" then |
06 | isGoingLeft = true |
07 | while isGoingLeft do |
08 | if isGoingLeft = = false then |
09 | break |
10 | end |
11 | moveLeft() |
12 | if isGoingLeft = = true then |
13 | wait(. 25 ) |
14 | elseif isGoingLeft = = false then |
15 | break |