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

How do you make the damaging part of the script work?

punch = false
damage = true
plr = game.Players.LocalPlayer
while not plr.Character do
	wait()
end

plr:GetMouse().KeyDown:Connect(function(k)
	ctr = plr.Character
	hum = ctr:WaitForChild("Humanoid")
	LeftArm = ctr:WaitForChild("Left Arm")
	ctr = plr.Character
	PunchAnim = Instance.new("Animation")
	PunchAnim.AnimationId = "https://web.roblox.com/asset/?id=".."2523553984"--put id here
	PunchAnimTrack = hum:LoadAnimation(PunchAnim)
	Power = game.Players.LocalPlayer.PlayerGui.MenuGui.StatsFolder.StrengthValue.Value
	Strength = game.Players.LocalPlayer.PlayerGui.MenuGui.StatsFolder.Strength
	if k == "e" then
		if punch == false then
			punch = true
			damage = false
			PunchAnimTrack:Play()
			wait(0.5)
			punch = false
			damage = true
		end
	end
end)
while punch do
	LeftArm.Touched:Connect(function(hit)
		if damage == false then
		damage = true
		human = hit.Parent:WaitForChild("Humanoid")
		human:TakeDamage(Power)
		wait(0.5)
		damage = false
	end
	end)
end

This is the script I used. Yes, I have tried printing and I don't seem to find the issue. No errors in output. The punching animation does work. If you know the answer to this, then tell me as soon as possible.

6 comments

0

Is this in a localscript?

0

yep

0

its in starterpack

1

Don't use KeyDown, it is deprecated. Use UserInputService instead.

0

If you want it to damage the player, you can just subtract from the player's health (found in the humanoid)

0

KeyDown is not a valid event of the player's Mouse because mice don't have keys

1 answer

✓ Accepted answer

Replace line 8 with:

plr:GetMouse().Button1Down:Connect(function(k)

The reason why I'm saying this is because the Player's Mouse object does not have an event named KeyDown. KeyDown is a deprecated event and should not be used. Methods similar to KeyDown (i.e. IsKeyDown()) are meant for keyboards and not computer mice.

A similar solution involves using the UserInputService to get the mouse input. The UserInputService is actually BETTER than the Mouse class with the reason being that the Mouse class is about to be deprecated. If using the UserInputService, use the method IsMouseButtonDown(). That'll help you out quite a bit.

2 comments

0

gonna user userinputservice now on and thx

0

i only accepted your answer because of userinputservice and Button1Down doesn't work. If you read my description it said the damaging part of the script

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