Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a Gui move Left and Right when you hold down a key, and then stop when you let go?

Asked by 2 years ago

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:

01local TweenService = game:GetService("TweenService")
02local Player = script.Parent.Parent
03local UIS = game:GetService("UserInputService")
04 
05game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
06 
07local jumpCooldown = 0.8
08local debounce = false
09 
10--//Player Movement\\--
11 
12UIS.InputBegan:Connect(function(Key)
13 
14    local PosX = Player.Position.X
15    local PosY = Player.Position.Y
View all 39 lines...

Any help on this?

2 answers

Log in to vote
3
Answered by 2 years ago

You can do this with UIS.InputBegan and UIS.InputEnded.

0
Yes, that could work, but I need to find a way to repeat where the Frame is going until the player stops holding the key down JackyW9cky 27 — 2y
0
just do an if statement with a loop and use else 666_brithday 103 — 2y
Ad
Log in to vote
1
Answered by 2 years ago

Use a variable. When UIS.InputBegan fires, the variable goes true. When UIS.InputEnded fires, the variable goes false. Then make a loop to check the variable value and move or stop that frame accordingly

Answer this question