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 » Scripting Helpers
Home Search
 

Re: OnKeyDown and OnKeyUp, not really my thing...

Previous Thread :: Next Thread 
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 02:58 PM
It's in a LocalScript, within a tool.Why doesn't it work?(There is no output since it is a Local Script.)

on = 0
Tool = script.Parent
local player = game.Players:GetPlayerFromCharacter(Tool.Parent)

function Key(key)
if key then
key = string.lower(key)
if (key=="f") then
on=1
end
end
end

function UP(key)
if key then
key = string.lower(key)
if (key=="f") then
on=0
end
end
end

while on==1 do
wait(0.1)
if player.Class.Value == "Sprint" then
player.Character.Humanoid.Walkspeed = 24
end
end

function Equip(mouse)
mouse.KeyDown:connect(Key)
mouse.KeyUp:connect(UP)
end
script.Parent.Equipped:connect(Equip)
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 03:06 PM
Bump
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
06 Aug 2012 03:09 PM
You need to connect the keydown function.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 03:09 PM
Move this to the keydown function after you set on to 1:
while on==1 do
wait(0.1)
if player.Class.Value == "Sprint" then
player.Character.Humanoid.Walkspeed = 24
end
end
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
06 Aug 2012 03:10 PM
Oops, excuse me last post, I didn't see the connector lines until after I posted it. D:
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 03:10 PM
I did, now anyone have anything actually helpfull?
Report Abuse
GreenDay987 is not online. GreenDay987
Joined: 21 May 2011
Total Posts: 7027
06 Aug 2012 03:11 PM
Jeez, I said I'm sorry, I just didn't see it.... >_>
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 03:12 PM
@droid
I don't understand your post, you mean move that chunk into the keydown function??
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 03:18 PM
Like this:
(Btw if it still doesn't work, then I'll attempt to just rewrite the script for you in my own style)

on = 0
Tool = script.Parent
local player = game.Players:GetPlayerFromCharacter(Tool.Parent)

function Key(key)
if key then
key = string.lower(key)
if (key=="f") then
on=1

while on==1 do
wait(0.1)
if player.Class.Value == "Sprint" then
player.Character.Humanoid.Walkspeed = 24
end
end

end
end
end

function UP(key)
if key then
key = string.lower(key)
if (key=="f") then
on=0
end
end
end

function Equip(mouse)
mouse.KeyDown:connect(Key)
mouse.KeyUp:connect(UP)
end
script.Parent.Equipped:connect(Equip)
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 03:25 PM
@droid
If I use this code is gives me the error:
16:24:38.776 - Players.Player.Backpack.Assualt Rifle-(30).Keys:13: attempt to index upvalue 'player' (a nil value)
16:24:38.776 - Script "Players.Player.Backpack.Assualt Rifle-(30).Keys", Line 13
16:24:38.776 - stack end
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 03:36 PM
local keyPressed = false;
script.Parent.Selected:connect(function (mouse)
mouse.KeyDown:connect(function (key)
key = key:lower();
if (key == "f") then
keyPressed = true;
while (keyPressed) do
local p = script.Parent.Parent.Parent;
if (not p:findFirstChild("Class")) then keyPressed = false; break; end
if (p.Class.Value == "Sprint") then
if (not p.Character) then keyPressed = false; break; end
p.Character.Humanoid.Walkspeed = 24;
end
end
p.Character.Humanoid.Walkspeed = 16;
end
end);
mouse.KeyUp:connect(function (key)
if (key == "f") then
keyPressed = false;
end
end);
end);
script.Parent.Deselected:connect(function () keyPressed = false; end);
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 03:37 PM
Oops, move local p = (etc) above the while (keyPressed) do line.
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 06:46 PM
It says this:
19:45:50.549 - Selected is not a valid member of Tool
19:45:50.550 - Script "Players.Player.Backpack.Assualt Rifle-(30).Keys", Line 2
19:45:50.550 - stack end

Mind you, this is in a tool, not a hopperbin.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 06:47 PM
Change Selected and Deselected to Equipped and Uneqiupped (I think? Idk I don't use tools).
Report Abuse
huner2 is not online. huner2
Joined: 27 Apr 2008
Total Posts: 1681
06 Aug 2012 06:49 PM
That's what I did anyway, I just figured out that posting that was stupid. >_>
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 06:49 PM
Lol :P Did it work?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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