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

RE: keyDown even not working?

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

local mouse = game.Players.LocalPlayer:GetMouse();
mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key=="z" then
		leftpunch()
		if leftpunch():onTouched(player) then
			local hum = player:findFirstChild("Humanoid")
			player.Humanoid.Health:TakeDamage(damage)
		end
	end
end)

Help! When I press z, it does nothing.

1 answer

Some of this script is kind of... not good. The arm would completely disconnect from the body if you were to use the z button... I just edited the script to your original preferences but I am not exactly sure about character arm placements to be honest.

local damage = 5
local player = game.Players.LocalPlayer --You forgot to define player.

function leftpunch()
local leftarm = player.Character:findFirstChild("Left Arm") --When you said left punch in this line, it thought you meant the function.
leftarm.Position = Vector3.new(30.422, 179.001, 138.099) --It's the Left Arm's Position
leftarm.Rotation = Vector3.new(90.161, 17.144, -53.438)
wait(1)
leftarm.Position = Vector3.new(37.5, 179.8, 146.003)
leftarm.Rotation = Vector3.new(179.669, -0, 180) -- At this point, the arm would be disconnected...
	leftarm.Touched:connect(object) --Touched event, if it were to somehow hit someone. Plus, don't mix the tags of player.
		local hum = object.Parent:findFirstChild("Humanoid") --The object that hit is not the parent of humanoid, its parent is.
		object.Parent.Humanoid:TakeDamage(damage)
	end
end

local mouse = game.Players.LocalPlayer:GetMouse() --There shouldn't have been a semicolon.
mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key=="z" then
        leftpunch()
    end
end)

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