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: KeyUp:connect doesn't work

Previous Thread :: Next Thread 
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
01 Feb 2014 06:37 AM
I'm currently working on my own Animation script, but this last part doesn't work.
I've been trying everything, and my analysing conclusion is that mouse.KeyUp:connect(onKeyUp) doesn't work. The local script is in StarterGui, and connects to the player. things you should know:

local mouse = script.Parent.Parent:GetMouse()
local myHumanoid = scipt.Parent.Parent.Character:findFirstChild("Humanoid")

mouse.KeyDown:connect(onKeyDown) does work.

this is the part of the script that doesn't;

function onKeyUp(key)
local myHumanoid = script.Parent.Parent.Character:findFirstChild("Humanoid")
key = key:lower()
if key == "w" and key == "a" and key == "s" and key == "d" then
local loadanim = myHumanoid:LoadAnimation(run)
loadanim:Stop()
wait(0.2)
myHumanoid.Parent:findFirstChild("Animate").Disabled = false
end
end
mouse.KeyDown:connect(onKeyDown)
mouse.KeyUp:connect(onKeyUp)



Report Abuse
funnymouse7 is not online. funnymouse7
Joined: 17 Mar 2011
Total Posts: 1741
01 Feb 2014 06:44 AM
if key == "w" and key == "a" and key == "s" and key == "d" then

???
so you want the player to press w and a and s and d all at the exact same time?

I think you mean to use the or operator like this

if key == "w" or key == "a" or key == "s" or key == "d" then


that should fix it
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
01 Feb 2014 07:14 AM
No, the thing is, it must be if key == "w" and key == "a" and key == "s" and key == "d" then . If players will be walking, and they press A while holding W, then release W, it'll bug. Therefor, it must be if key == "w" and key == "a" and key == "s" and key == "d" then
Also, do know that the entire script works entirely perfect. It's just the connection. Also, if key == "w" and key == "a" and key == "s" and key == "d" then means that all buttons must be up (Or, not walking). That means it's, well, correct. But thank you for trying to help.
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
01 Feb 2014 07:33 AM
Bump
Report Abuse
Virtual3D is not online. Virtual3D
Joined: 15 Jan 2009
Total Posts: 634
01 Feb 2014 08:18 AM
As far as I know, you can't have a key be two different keys. When you press a key the script use that one key. Any other keys pressed will run a separate function.
Report Abuse
BEART12 is not online. BEART12
Joined: 22 Oct 2008
Total Posts: 3190
01 Feb 2014 08:29 AM
if key == "w" or key == "a" or key == "s" or key == "d" then
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
01 Feb 2014 12:38 PM
Not exactly. For there is a different part of my script for the KeyDown, goes like this:

function onKeyDown(key)
key=key:lower()
if key=="w" or key=="a" or key=="s" or key=="d" then
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
03 Feb 2014 08:36 AM
Bump
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
04 Feb 2014 04:03 AM
Bump
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
04 Feb 2014 04:55 AM
I don't have much knowledge with setting keys, but I think it should be

if not (key~="w") and (key~="a") and (key~="s") and (key~="d") then
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
04 Feb 2014 05:39 AM
I can try.
Report Abuse
GrandAwsome is not online. GrandAwsome
Joined: 12 Jul 2011
Total Posts: 326
04 Feb 2014 06:26 AM
I find this silly...

How can a certain key equal multiple keys?

this is like saying:
num = 5
if num == 5 and num == 10 and num == 13 then

No matter what num is, it will never pass the if statement.

All the keyup connection does is call the function when a key is unpressed, If the 4 keys are unpressed, then the function is called 4 times. The only argument given to your function is the 1 key that is unpressed in that time.

So, what you you're doing is impossible without using some global variables(not _G, global variables, as in outside the function environment)

Alt. of Jetta765214
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
04 Feb 2014 06:29 AM
Well, if my earlier suggestion doesn't work (as I doubt it will), the next thing I can think of is inserting the keys pressed in a table, and remove them once unpressed.
Report Abuse
Vyxium is not online. Vyxium
Joined: 31 Aug 2010
Total Posts: 1020
04 Feb 2014 09:02 AM
your second variable is spelled wrong when defining the humanoid, you said "scipt" instead of "script" (you forgot the r)
Report Abuse
Vyxium is not online. Vyxium
Joined: 31 Aug 2010
Total Posts: 1020
04 Feb 2014 09:05 AM
you can have multiple keys set up to fire a function...
Report Abuse
thelolguy301 is not online. thelolguy301
Joined: 27 Sep 2011
Total Posts: 2997
04 Feb 2014 11:24 AM
The additional information such as loca myHumanoid was not directly copied from the script. In the actual script, I didn't make any typing mistakes, or I would notice this in the output.
Report Abuse
Vyxium is not online. Vyxium
Joined: 31 Aug 2010
Total Posts: 1020
04 Feb 2014 11:40 AM
i figured, but it wouldnt show up in the output for the game would think "scipt" is a variable itself
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
04 Feb 2014 01:32 PM
local KeysDown = {}
setmetatable(KeysDown,{
__call = function(s,...)
for _,n in pairs({...}) do
if not s[n:lower()] then
return false
end
end
return true
end
})

local Player = Game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(key)
KeysDown[key:lower()] = true
if KeysDown("w","s","a","d") then
--Magic
end
end)

Mouse.KeyUo:connect(function(k)
KeysDown[k:lower()] = false
end)
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