Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

keyDown event not working?

Asked by 11 years ago
01local player = game.Players.LocalPlayer
02mouse = player:GetMouse()
03 
04local damage = 5
05 
06 
07function leftpunch()
08    local leftpunch = player:findFirstChild("Left Arm")
09leftpunch.Position.Vector3.new(30.422, 179.001, 138.099)
10leftpunch.Rotation.Vector3.new(90.161, 17.144, -53.438)
11wait(1)
12leftpunch.Position.Vector3.new(37.5, 179.8, 146.003)
13leftpunch.Rotation.Vector3.new(179.669, -0, 180)
14end
15 
View all 26 lines...

When you press z, you left punch, But it's not working. Why? Can you explain why too?

0
KeyDown is deprecated, and shouldn't be used anymore in any circumstance; use the UserInputService instead: http://wiki.roblox.com/index.php?title=API:Class/UserInputService :) TheeDeathCaster 2368 — 8y

2 answers

Log in to vote
-1
Answered by
KAAK82 16
11 years ago

put it into 1 function

01function KeyDown(key)
02    key:lower()
03    if key == 'z' then
04        --watever arm movements here
05        leftpunch.Touched:connect(function(hit)
06            h = hit.Parent:FindFirstChild('Humandoid')
07            if h ~= nil then
08                h:TakeDamage(damage)
09            elseif hit.Parent.Name == leftpunch.Parent.Name then
10                print('Player cannot Punch himself')
11            end
12        end
13    end
14end
15 
16mouse.KeyDown:connect(KeyDown)
0
I Helped u with this cos u gave the Script u trusted everyone to Fix it... u didn't say 'I want that kind of Script' so I helped, also, I see people Thumbs Down on ur Problem, I see nothing bad, so here ya go... also, I would Thumbs Up but cant cos my Reputation... KAAK82 16 — 11y
0
I didn't say I trusted them Roboy5857 20 — 11y
0
I kno... but u trusted people that u shared ur Script... hardly anyone these days does that... KAAK82 16 — 11y
0
Don't just post code; please explain the reasoning behind your answer, as others, and the OP, may/ will look at this answer and question why the answerer wrote the code as it is, and wont understand what changes occurred or what does what. (i.e. Why use KeyDown? Why do you need a function for it? Is the argument the mouse returned? Or is it the key?) TheeDeathCaster 2368 — 8y
Ad
Log in to vote
-2
Answered by 11 years ago

mouse is not an event. You need to do

1local mouse = game.Players.LocalPlayer:GetMouse();
2mouse.KeyDown:connect(function(key)
3    --key code
4end)
0
Please explain the reasoning behind your answer. Thanx c; TheeDeathCaster 2368 — 8y

Answer this question