How can I make a Gui move Left and Right when you hold down a key, and then stop when you let go?
So, I had a cool idea to make a 2D Roblox Game only using Guis. I've seen one YouTuber do it before, and I wanted to try and make my own version. Everything was going great until I ran into a problem.
In my game, I set both the Player's WalkSpeed and JumpPower to 0, then inserted a Frame inside of a ScreenGui in the StarterGui.
Then, I made a LocalScript inside of the Frame that controls the Frame's movement.
However, when I tested the game out and clicked the "A" and "D" keys (which are used to control the Frame to go Left and Right), it would only let me go a certain distance before stopping, even though I was still holding down the key for that direction.
What I am trying to do is to get the Frame to Copy Roblox's Actual movement system, like when you hold down the "W" key, your character moves forwards until you let go of the "W" key.
What my Frame is doing is it is stopping at a certain distance even though I am still holding down the key.
This is the Frame's Gui Movement LocalScript:
01 | local TweenService = game:GetService( "TweenService" ) |
02 | local Player = script.Parent.Parent |
03 | local UIS = game:GetService( "UserInputService" ) |
05 | game:GetService( "StarterGui" ):SetCoreGuiEnabled(Enum.CoreGuiType.All, false ) |
07 | local jumpCooldown = 0.8 |
12 | UIS.InputBegan:Connect( function (Key) |
14 | local PosX = Player.Position.X |
15 | local PosY = Player.Position.Y |
17 | if Key.KeyCode = = Enum.KeyCode.W and Player.Position ~ = UDim 2. new(PosX.Scale, 0 , 0.1 , 0 ) or Key.KeyCode = = Enum.KeyCode.D and Player.Position ~ = UDim 2. new(PosX.Scale, 0 , 0.1 , 0 ) then |
19 | Player:TweenPosition(UDim 2. new(PosX.Scale + 0.1 , 0 , PosY.Scale, 0 ), "Out" , "Linear" , 0.2 ) |
23 | if Key.KeyCode = = Enum.KeyCode.S and Player.Position ~ = UDim 2. new(PosX.Scale, 0 , 0.1 , 0 ) or Key.KeyCode = = Enum.KeyCode.A and Player.Position ~ = UDim 2. new(PosX.Scale, 0 , 0.9 , 0 ) then |
25 | Player:TweenPosition(UDim 2. new(PosX.Scale - 0.1 , 0 , PosY.Scale, 0 ), "Out" , "Linear" , 0.2 ) |
29 | if Key.KeyCode = = Enum.KeyCode.Space and Player.Position ~ = UDim 2. new(PosY.Scale, 0 , 0.6 , 0 ) then |
30 | if debounce = = false then |
32 | Player:TweenPosition(UDim 2. new(PosX.Scale, 0 , PosY.Scale - 0.4 , 0 ), "Out" , "Sine" , 0.6 ) |
34 | Player:TweenPosition(UDim 2. new(PosX.Scale, 0 , PosY.Scale + 0.01 , 0 ), "Out" , "Bounce" , 0.8 ) |
Any help on this?