|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|