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: Help KeyDown

Previous Thread :: Next Thread 
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 01:41 AM
p = game.Players.LocalPlayer
c = p.Character
joint = c.Armor.Other
repeat wait() until p
p:GetMouse().KeyDown:connect(function(key)
if key:lower() == "w" then
script.Parent.Running.Value = true
end
end)
p:GetMouse().KeyDown:connect(function(key)
if key:lower() == "a" then
script.Parent.Running.Value = true
end
end)
p:GetMouse().KeyDown:connect(function(key)
if key:lower() == "s" then
script.Parent.Running.Value = true
end
end)
p:GetMouse().KeyDown:connect(function(key)
if key:lower() == "d" then
script.Parent.Running.Value = true
end
end)

p:GetMouse().KeyUp:connect(function(key)
if key:lower() == "w" then
script.Parent.Running.Value = false
end
end)
p:GetMouse().KeyUp:connect(function(key)
if key:lower() == "a" then
script.Parent.Running.Value = false
end
end)
p:GetMouse().KeyUp:connect(function(key)
if key:lower() == "s" then
script.Parent.Running.Value = false
end
end)
p:GetMouse().KeyUp:connect(function(key)
if key:lower() == "d" then
script.Parent.Running.Value = false
end
end)


while wait() do
if script.Parent.Running.Value == false then
c.Stand.Disabled = false
c.Walk.Disabled = true

elseif script.Parent.Running.Value == true then

c.Stand.Disabled = true
c.Walk.Disabled = false

end
end

So everything works except, if I'm pressing 2 keys at the same time, and lift one up, c.Stand.Disabled is set to false. How can I bypass that?
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 01:46 AM
bump
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 01:51 AM
help
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:00 AM
bump
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:14 AM
I'm guessing you're trying to make a script enabled only when a character is moving?
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:15 AM
^Yes, and when player stops is disables it.
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:19 AM
http://wiki.roblox.com/index.php?title=Running_(Event)
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:20 AM
^ I tried that but doesn't seem to work..
c = script.Parent.Parent.Character
Humanoid = c.Humanoid
Humanoid.Running:connect(function(speed)

if speed>0 then
c.Walk.Disabled = false

else
c.Stand.Disabled = false
end
end)
while wait() do
if c.Stand.Disabled == false then
c.Walk.Disabled = true
elseif c.Walk.Disabled == false then
c.Stand.Disabled = true
end
end
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:26 AM
Alright, so it fires when a humanoid starts running, and when it stops. So...


game.Workspace.Player.Humanoid.Running:connect(function(speed)
if speed > 0 then
print("Player is running")
else
print("Player has stopped")
end
end)


Now, we want to enable one script when one is walking, and disable it when one stops walking, so...


game.Workspace.Player.Humanoid.Running:connect(function(speed)
if speed > 0 then
print("Player is running")
script1.Disabled = false
else
print("Player has stopped")
script1.Disabled = true
end
end)


Does that explain it?
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:27 AM
Yes so,
c = script.Parent.Parent.Character
Humanoid = c.Humanoid
Humanoid.Running:connect(function(speed)
if speed > 0 then
c.Walk.Disabled = false
c.Stand.Disabled = true
else
c.Stand.Disabled = false
c.Walk.Disabled = true
end
end)
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:29 AM
Precisely. Just make sure c actually gets the character, and the character has the scripts "Walk" and "Stand," and that should do it.
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:31 AM
No work
c = script.Parent.Parent.Character
repeat wait() until c
Humanoid = c.Humanoid
repeat wait() until Humanoid
repeat wait() until c.Walk
repeat wait() until c.Stand
Humanoid.Running:connect(function(speed)
if speed > 0 then
c.Walk.Disabled = false
c.Stand.Disabled = true
else
c.Stand.Disabled = false
c.Walk.Disabled = true
end
end)
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:35 AM
Try this:



repeat wait() until script.Parent.Parent.Character
c = script.Parent.Parent.Character

repeat wait() until c:findFirstChild("Humanoid")
Humanoid = c.Humanoid

repeat wait() until c:findFirstChild("Walk")
repeat wait() until c:findFirstChild("Stand")

Humanoid.Running:connect(function(speed)
if speed > 0 then

c.Walk.Disabled = false
c.Stand.Disabled = true

else

c.Stand.Disabled = false
c.Walk.Disabled = true

end
end)
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:38 AM
Doesn't work
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:40 AM
What's wrong? Are any of the scripts being disabled/enabled? I tested the event and it works.
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 02:42 AM
Bah, g2g to sleep. G'Luck, I'll try to see what I can do tomorrow.
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 02:43 AM
Only Stand.Disabled works..
Walk doesn't change
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 11:40 AM
Bumping this so someone else can try to help.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
24 Jun 2014 11:41 AM
so unorganized, not helping.
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 11:52 AM
In my last script post, there was one event and one if statement. I'm not sure how much more organized it could be.
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
24 Jun 2014 11:55 AM
You dont need to many KeyUp and KeyDown events.. just put

elseif key:lower() == blah then
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 11:58 AM
Good grief why is everyone only reading the first post:



repeat wait() until script.Parent.Parent.Character
c = script.Parent.Parent.Character

repeat wait() until c:findFirstChild("Humanoid")
Humanoid = c.Humanoid

repeat wait() until c:findFirstChild("Walk")
repeat wait() until c:findFirstChild("Stand")

Humanoid.Running:connect(function(speed)
if speed > 0 then

c.Walk.Disabled = false
c.Stand.Disabled = true

else

c.Stand.Disabled = false
c.Walk.Disabled = true

end
end)
Report Abuse
theroadrunner is not online. theroadrunner
Joined: 06 Oct 2010
Total Posts: 862
24 Jun 2014 12:07 PM
Last bump.
Report Abuse
legojoker is not online. legojoker
Joined: 23 Sep 2008
Total Posts: 120
24 Jun 2014 12:36 PM
Btw for future reference Tynexx, have only 1 GetMouse event connection, and have an if then with several elseifs to test for other keys. Also, an easy way to solve your problem is to have a variable like local numKeys = 0 and every time a keydown is called make numKeys = numKeys+1 and every time a key comes up make numKeys = numKeys-1 and make it so it only disables itself when numKeys is updated to be = 0. Hope this helped.
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
24 Jun 2014 12:37 PM
^ Oh, thank you :D
I'll try it
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