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

How do I make the LeftPunch function do damage?

I am trying to make the LeftPunch function do damage. But I can't figure it out. I would love it if someone helped me!

Player = game.Players.LocalPlayer
Character = Player.Character
Mouse = Player:GetMouse()

LeftShoulder = Character.Torso["Left Shoulder"]
RightShoulder = Character.Torso["Right Shoulder"]
LeftHip = Character.Torso["Left Hip"]
RightHip = Character.Torso["Right Hip"]

function LeftPunch(key)
	Key = key:lower()
	if Key == "q" then
		for i = 1, 1 do
			for i = 1, 10 do
				LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, -0.25)
				wait()
			end
			for i = 1, 10 do
				LeftShoulder.C0 = LeftShoulder.C0 *CFrame.Angles(0, 0, 0.25)
				wait()
			end
		end
	end	
end

function RightPunch()
	
end

function LeftKick()
	
end

function RightKick()
	
end

Mouse.KeyDown:connect(LeftPunch)

1 answer

✓ Accepted answer

With the arm, you could connect the Touched event to the arm.

To enforce the damage, we could employ the TakeDamage function of a Humanoid. The code would end up looking something like (with your current code):

local arm = Character['Left Arm'];
arm.Touched:connect(function(hit)
if not(hit.Parent:FindFirstChild'Humanoid') then return end;
hit.Parent.Humanoid:TakeDamage(13);
end);

Also, if you want to have the damage stored at the top in a variable, you could do that.

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