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

How can I make my punch animation do damage?

humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
right = script:WaitForChild("RightPunch")
left = script:WaitForChild("LeftPunch")
idle = script:WaitForChild("Idle")
enabled = false
Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.KeyDown:connect(function(key)
	if key == 'y' then
		local anim = humanoid:LoadAnimation(idle)
		if enabled == false then
			print ('Stance Enabled')
			anim:Play()
			enabled = true
		elseif enabled == true then
			anim:Stop()
			enabled = false
		end
	end
	
	if key == 'e' then 
		local anim = humanoid:LoadAnimation(right)
		if enabled == true then
			anim:Play()
			wait(0.6)
		else
			print('Not in stance')
		end
	elseif key == 'q' then
		local anim = humanoid:LoadAnimation(left)
		if enabled == true then
			anim:Play()
			wait(0.6)
		else
			print('Not in stance')
		end
	end
	
end)

What do I add to this to make it do damage?

2 comments

0

I am going to use this.

0

Feel Free

1 answer

LocalScript :

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) --your remote event
        end
    end
end)

You will need to create a RemoteEvent

In the ServerScript you write something like :

 game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(plr , hit)

hit:TakeDamage(10)

end)

2 comments

0

Very insecure

0

It says "unknown global db" and "global damage is only used when enclosing the function consider changing it to local"

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