|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|