Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

keyDown event not working?

local player = game.Players.LocalPlayer
mouse = player:GetMouse()

local damage = 5


function leftpunch()
	local leftpunch = player:findFirstChild("Left Arm")
leftpunch.Position.Vector3.new(30.422, 179.001, 138.099)
leftpunch.Rotation.Vector3.new(90.161, 17.144, -53.438)
wait(1)
leftpunch.Position.Vector3.new(37.5, 179.8, 146.003)
leftpunch.Rotation.Vector3.new(179.669, -0, 180)
end

function keyDown(key)
	if key=="z" then
		leftpunch()
		if leftpunch():onTouched(player) then
			local hum = player:findFirstChild("Humanoid")
			player.Humanoid.Health:TakeDamage(damage)
		end
	end
end

script.Parent.mouse:connect(keyDown)

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

1 comment

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

2 answers

put it into 1 function

function KeyDown(key)
	key:lower()
	if key == 'z' then
		--watever arm movements here
		leftpunch.Touched:connect(function(hit)
			h = hit.Parent:FindFirstChild('Humandoid')
			if h ~= nil then
				h:TakeDamage(damage)
			elseif hit.Parent.Name == leftpunch.Parent.Name then
				print('Player cannot Punch himself')
			end
		end
	end
end

mouse.KeyDown:connect(KeyDown)

4 comments

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

0

I didn't say I trusted them

0

I kno... but u trusted people that u shared ur Script... hardly anyone these days does that...

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

mouse is not an event. You need to do

local mouse = game.Players.LocalPlayer:GetMouse();
mouse.KeyDown:connect(function(key)
	--key code
end)

1 comment

0

Please explain the reasoning behind your answer. Thanx c;

This discussion is preserved as it was. New answers, comments, and votes are closed.