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

How to LeftClick To Punch?

What Keycode For Left Click here script for punch :

local player = game.Players.LocalPlayer
local db = true
local damage = false

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset?id=3582012915"

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not db and not damage and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
		if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
			damage = true
			game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
		end
	end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, event)
	if input.KeyCode == Enum.KeyCode.F and db then
		db = false
		local playAnim = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):loadAnimation(anim)
		playAnim:Play()
		wait(0.8)
		damage = false
		db = true
	end
end)

5 comments

0

can you please use the code block on the website. it makes things easier for everybody

0

edited

0

MouseButton1

0

But it isn't a KeyCode because mouse buttons aren't keys. Mouse buttons are input types.

0

oh

1 answer

✓ Accepted answer

It's not a keycode you're looking for (because the mouse doesn't have keys), but a UserInputType: if input.UserInputType == Enum.UserInputType.MouseButton1

1 comment

0

Thanks You ^^

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