|
| 31 Oct 2015 04:03 AM |
Um i need help fixing this script that will move my gui frame up or down by 1, each time i press A or D:
local M = game.Players.LocalPlayer:GetMouse()
M.KeyDown:connect(function(key) if string.lower(key) == "d" then print("D") while string.lower(key) == "d" do local i = 0.01 script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.25-i ,0) end end end end) |
|
|
| Report Abuse |
|
|
HRnSN
|
  |
| Joined: 22 Jun 2009 |
| Total Posts: 1276 |
|
|
| 31 Oct 2015 05:01 AM |
M.KeyDown:connect(function(key) local i = 0.01 if string.lower(key) == "d" then script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.25-i ,0) elseif string.lower( key ) == "a" then script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.25+i ,0) end end) |
|
|
| Report Abuse |
|
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 31 Oct 2015 05:03 AM |
you're better off adjusting the offset - I don't think you need a while loop as it is a KeyDown event and 'i' never changes. Try defining 'i' outside the keydown function. 'A' and 'D' are used for movement already? better to include Text or Image Buttons within your Gui then script using mouse clicks on the gui buttons.
Sorry I didn't know there were so many issues when i started typing.
Where's my chips? |
|
|
| Report Abuse |
|
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 31 Oct 2015 05:11 AM |
Do you want the frame to 'jiggle' up and down a small amount or to be able to position it anywhere vertically on the screen. For the former 'i' doesn't need to change, for the latter you need an incremental: i = i + 0.01 or i = i + 1 / i = i - 1 etc. in your code somewhere
Where's my chips? |
|
|
| Report Abuse |
|
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 31 Oct 2015 05:16 AM |
Sorry HRnSN hadn't realised you had already replied - regards
Where's my chips? |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 09:20 AM |
Welp its still doing the same thing, I want it to move um or down every time I hold or press w or s... Fix it for me please:
local M = game.Players.LocalPlayer:GetMouse() M.KeyDown:connect(function(key) local i = 1 if string.lower(key) == "w" then i = i + 1 script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.1 ,0-i) wait(1) elseif string.lower( key ) == "s" then i = i + 1 script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.1 ,0+i) wait(1) end end)
|
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 09:35 AM |
Maybe something like this
local InputService = game:GetService("UserInputService")
local Keys = {}
InputService.InputBegan:connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.Keyboard then print("Key is held down") end Keys[InputObject.KeyCode] = true end)
InputService.InputEnded:connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.Keyboard then print("Key is released") end Keys[InputObject.KeyCode] = false end)
if Keys[Enum.KeyCode.A] then
end
if Keys[Enum.KeyCode.D] then
end |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 04:49 PM |
| Yea, I need a script ill understand.. |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 05:26 PM |
| Umm, all these views but barely help |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 07:12 PM |
local Keys = {} -- setting a table (will contain keys we hold)
InputService.InputBegan:connect(function(InputObject) -- When an input happens if InputObject.UserInputType == Enum.UserInputType.Keyboard then -- When an input from the keyboard happens print("Key is held down") -- print a key was held down Keys[InputObject.KeyCode] = true -- add a key to the table that contains keycode and set that key's value to true end end)
InputService.InputEnded:connect(function(InputObject) -- when an input ends if InputObject.UserInputType == Enum.UserInputType.Keyboard then -- when an input from the keyboard ends print("Key is released") -- print the key was released Keys[InputObject.KeyCode] = false -- set the key in the table's value to false, so we know the key was released end end)
if Keys[Enum.KeyCode.A] then -- if key a is held down -- do things end
if Keys[Enum.KeyCode.D] then -- if key d is held down -- do things end
Look up: UserInputService |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 10:14 PM |
| umm I get that, I just used the easier way.. I want to know how to add a value to the position on key press everytime |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 11:07 PM |
boss, I was just wondering about what you said.
you put:
if Keys[Enum.KeyCode.A] then end
However, I'm used to believing that would only check if it was true once in that context.
Am I wrong?
Otherwise doesn't it need to be in a loop? |
|
|
| Report Abuse |
|
|
|
| 31 Oct 2015 11:10 PM |
| Yeah it needs to be in a loop. I just looked at some random code I had for some horrible GUI Player I made. |
|
|
| Report Abuse |
|
|
|
| 01 Nov 2015 01:35 AM |
| Boss I get your way because that's the first way I used, but I'm trying to make the Position.Y go up or down for the frame every time I push W or S... |
|
|
| Report Abuse |
|
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 01 Nov 2015 04:21 AM |
AlertedDynamite just for clarification if you press A once you want to move the frame up by (say) five pixels; and if you press A again you want it to move another five pixels higher; or do you want it 'docked' at the higher position until 'D' is pressed and it will revert back to its original position? I'm trying to understand exactly what you want. Regards
Where's my chips? |
|
|
| Report Abuse |
|
|
|
| 01 Nov 2015 10:51 AM |
| The first thing you said ;) |
|
|
| Report Abuse |
|
|
|
| 01 Nov 2015 12:59 PM |
| All of these views and barely replys |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 01 Nov 2015 09:51 PM |
M.KeyDown:connect(function(key) local i = 0.01 if string.lower(key) == "d" then script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.25-i ,0) elseif string.lower( key ) == "a" then script.Parent.Frame.Frame.Position = UDim2.new(0.462, 0, 0.25+i ,0) end end)
This one that was previously said would seem to work.
|
|
|
| Report Abuse |
|
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 02 Nov 2015 02:31 PM |
this works
local gui = script.Parent.ScreenGui local frame = gui:FindFirstChild("Frame")
--Um i need help fixing this script that will move my gui frame up or down by 1, each time i press A or D:
local M = game.Players.LocalPlayer:GetMouse() local i = 0
M.KeyDown:connect(function(key) if string.lower(key) == "d" then print("D") i = i + 0.01 elseif string.lower(key) == 'a' then print('A') i = i - 0.01 end frame.Position = UDim2.new(0.462, 0, 0.25+i ,0)
end)
Where's my chips? |
|
|
| Report Abuse |
|
|
| |
|
tapuzi
|
  |
| Joined: 05 Jul 2014 |
| Total Posts: 162 |
|
|
| 03 Nov 2015 11:06 AM |
gui = Instance.new('ScreenGui',script.Parent) frame = Instance.new('Frame',gui) frame.Size = UDim2.new(0,100,0,100) frame.Position = UDim2.new(0.462, 0, 0.25,0) label = Instance.new('TextLabel',frame) label.Size = UDim2.new(1,0,1,0) label.Text = "Press 'A' or 'D' to change the vertical posn of this box" label.TextWrapped = true
local M = game.Players.LocalPlayer:GetMouse() local i = 0 mode = 'active'
M.KeyDown:connect(function(key) if mode == 'inactive' then mode = 'active' end while mode == 'active' do if string.lower(key) == "d" then print("not fakeD") i = i + 0.01 elseif string.lower(key) == 'a' then print('A help') i = i - 0.01 end frame.Position = UDim2.new(0.462, 0, 0.25+i ,0) wait(0.3) end -- while loop end) -- function
M.KeyUp:connect(function(key) if mode == 'active' then mode = 'inactive' end end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 03 Nov 2015 08:10 PM |
| oh sht... How much robux you want... 1-3219? |
|
|
| Report Abuse |
|
|