generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Script that moves a GUI using WASD

Previous Thread :: Next Thread 
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
26 Jan 2016 04:15 PM
I want to make a mario game and I need a GUI will move in a certain direction with keypress
I made 4 but they dont work, can someone help?
Report Abuse
madsenbenjamin is not online. madsenbenjamin
Joined: 22 Jun 2011
Total Posts: 96
26 Jan 2016 04:23 PM
Are you using something like this?

function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
//stuff to do
end
end

function onKeyRelease(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
//stuff to do
end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyRelease)

For each of those, put "if inputObject.KeyCode == Enum.KeyCode.W/A/S/D" and if you want to move gui while one is pressed, then make a pressed boolean for each of the keys that changes when the key is pressed or released and have something connected to RenderStepped or something that moves the gui in different directions based on what keys are pressed.


Report Abuse
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
26 Jan 2016 04:28 PM
No, I did this
-------------------------------------------
sprite = script.Parent.Box;
Player = game.Players.LocalPlayer;
Mouse = Player:GetMouse();
Open = false;

function PressQ(key)
if (key == "q") then Open = true; repeat wait()
sprite.Position = sprite.Position - UDim2.new(0.01,0,0,0)
until (key == "e")
end
end
Mouse.KeyDown:connect(PressQ)
-----------------------------------------------

Report Abuse
madsenbenjamin is not online. madsenbenjamin
Joined: 22 Jun 2011
Total Posts: 96
26 Jan 2016 04:29 PM
So wait, do you want the gui to be constantly moving, but the direction changed by keys pressed?


Report Abuse
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
26 Jan 2016 04:32 PM
I want to make a Mario game (2D and purely GUIs) Q moves him left and E moves him right, the sprite has to move when the key is pressed or held down, and stop when the key stops being pressed
Report Abuse
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
26 Jan 2016 04:34 PM
I made another script similar to yours but the problem is that it isnt continuous, it's just single tetris movements, and when I do a repeat until, for some reason it doesnt work
Report Abuse
xlaser23 is not online. xlaser23
Joined: 10 Dec 2011
Total Posts: 20341
26 Jan 2016 04:46 PM
game:GetService("UserInputService").InputBegan:connect(function(Key)
if Key.KeyCode == Enum.KeyCode.Q then
--dostuff
end
end)



http://www.roblox.com/xla-item?id=290739801http://www.roblox.com/aser-item?id=290739819http://www.roblox.com/23-item?id=290739831 R$1,403 Tx288 (づ ゚ ³ ゚)づ
Report Abuse
madsenbenjamin is not online. madsenbenjamin
Joined: 22 Jun 2011
Total Posts: 96
26 Jan 2016 05:00 PM
Do what I said above with booleans
for example:

local qpressed = false

function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
qpressed = true
end
end

function onKeyRelease(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
qpressed = false
end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyRelease)

and then for the movement to the left:

game:GetService("RunService").RenderStepped:connect(function()
if qpressed then
sprite.Position = sprite.Position - UDim2.new(0.01,0,0,0)
end
end)


Report Abuse
Bernkastel2727 is not online. Bernkastel2727
Joined: 23 Sep 2012
Total Posts: 2612
26 Jan 2016 05:27 PM
Thank you so much Benjamin, I've been messing with this for weeks and I finally got it! thx!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image