|
| 29 Jun 2012 10:51 AM |
How exactly would I make a script that works only when a key is HELD DOWN, and not pressed? Is there a certain function for that? Also, how would I go about making it so that the script only works for let's say, 5 seconds before you have to let go of the key and press it again..?
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Jun 2012 10:55 AM |
Hmm....
function okd(key) key = key:lower() --Stuff end
if okd() then while wait(2) do print("okay") if not okd() then break end end end I don't know the connection line and I'm not sure if you can make a function be checked. :/ |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 10:57 AM |
:\
Oh well.... I'll go back to my other problems, then. This one seems to be destined to be left for the future.
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Jun 2012 10:59 AM |
Sorry, actually :o you can maybe(Big maybe) look at the plugin ROBLOX made for moving players in %appdata% >> Local >> Roblox It might not be there but then again, it might be o.O |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:01 AM |
Thanks, I'll try that :P
Now go help me in my other onKeyDown thread: http://www.roblox.com/Forum/ShowPost.aspx?PostID=71032691
nao :o
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:01 AM |
Here's an example:
local keyheld = false mouse.KeyDown:connect(function(key) keyheld = true print("held") end) mouse.KeyUp:connect(function(key) keyheld = false print("released") end) |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:04 AM |
Oh, and for your second question:
local keyheld = false mouse.KeyDown:connect(function(key) if not keyheld then wait(5) end keyheld = true print("held") end) mouse.KeyUp:connect(function(key) keyheld = false print("released") end) |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:07 AM |
@Electric
Would I add that on to my existing script for onKeyDowns?:
local player = Game.Players.LocalPlayer local keyFunctions={ ["x"]=function() player.PlayerGui.ScreenGui.Frame.Visible = true end; } script.Parent.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) local key=key:lower() if keyFunctions[key] then keyFunctions[key]() end end) end)
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:08 AM |
| @Greenday - That was just an example. It was meant to show you that KeyDown fires when you click, and KeyUp fires when you release. What do you want to happen when you click, and what do you want to happen when you release? |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:12 AM |
The script I use is for a "sprinting" feature in my FPS, but I realized people can press "E" and sprint forever, so I want it to have to be held, then after 5 seconds they become "tired" and must let go and "recharge" for 10 seconds before they can sprint again...
The script I posted was wrong, it was for opening an Option GUI, sorry. This one is for the sprinting:
local player = Game.Players.LocalPlayer local keyFunctions={ ["e"]=function() script.Parent.Parent.Humanoid.WalkSpeed = 100 end; } script.Parent.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) local key=key:lower() if keyFunctions[key] then keyFunctions[key]() end end) end)
And that is in a script that is undisabled when a button in the options screen is clicked. The only other problem is that I have to unequip and reequip the gun I use for these so that sprinting works, but that's another problem in another thread :P
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:18 AM |
But to keep it simple, answer the first part. That script is basically how all of my onKeyDowns work, so I would need a complete different script for the sprinting feature?
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:18 AM |
I'm just going to rewrite that whole script, it annoys me. :C
local player = game.Players.LocalPlayer repeat wait() until player local held = false script.Parent.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key:lower() == "e" then if not held then wait(5) end held = true player.Character.Humanoid.WalkSpeed = 100 end end) mouse.KeyUp:connect(function(key) if key:lower() == "e" then held = false player.Character.Humanoid.WalkSpeed = 16 end end) end) |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:20 AM |
I found it to be a nice template :P
Anyway, I see the "Equipped" part and now I have another question, since it seems that I have to unequip and reequip the gun just so it works, how would I fix that?
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:36 AM |
Bump.
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:39 AM |
| If you used the script I just posted, that shouldn't happen. I tested it, and I didn't have to reequip it. |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:40 AM |
Hm. Okay, I'll try it out. Hopefully it works, I've been having the issue of needing a script fixed and SH takes 7 hours to reply. It's like nobody sees the "My Forums" button up there...
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
WhiteRain
|
  |
| Joined: 24 Apr 2010 |
| Total Posts: 2723 |
|
|
| 29 Jun 2012 11:48 AM |
| add wait() at the top of the localscript. |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:49 AM |
| @White - ...There is a wait... |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:49 AM |
It apparently doesn't work. I press "X" and the Options comes up, then I press the button used to undisable the script you gave me, then I hold "e" and try to walk and it doesn't go faster. It did one time, but I kept holding "E" and I ran forever, and sometimes it doesn't work :\
Glitchy....
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:52 AM |
| @Green - You have to wait 5 seconds for it to work. Remember? And yes, it does go forever. You have to wait 5 seconds after you let go. Isn't that what you wanted? |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:53 AM |
Actually, I wanted it to work for 5 seconds, then it stops working and you have to recharge for 10 and then it works again. Sorry, it is very confusing.... no wonder people didn't reply to any of my threads :C
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 11:58 AM |
The problem I think is the GUI. It still seems to not allow the key to work without re-equipping.
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 12:00 PM |
Oh.
local player = game.Players.LocalPlayer repeat wait() until player local held = false script.Parent.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key:lower() == "e" then if not held then wait(10) end held = true player.Character.Humanoid.WalkSpeed = 100 wait(5) player.Character.Humanoid.WalkSpeed = 16 held = false end end) mouse.KeyUp:connect(function(key) if key:lower() == "e" then held = false player.Character.Humanoid.WalkSpeed = 16 end end) end) |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 12:01 PM |
Let me fix the indentations on that:
local player = game.Players.LocalPlayer repeat wait() until player local held = false script.Parent.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key:lower() == "e" then if not held then wait(10) end held = true player.Character.Humanoid.WalkSpeed = 100 wait(5) player.Character.Humanoid.WalkSpeed = 16 held = false end end) mouse.KeyUp:connect(function(key) if key:lower() == "e" then held = false player.Character.Humanoid.WalkSpeed = 16 end end) end) |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2012 12:06 PM |
It's still extremely glitchy.
It doesn't work immediately after I click the button, or sometimes at all and I hold it and it works for much longer than expected, and I can let go of "e" and it still works...
Complications ._.
-GD987, the FPS Developer- |
|
|
| Report Abuse |
|
|