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 add a damage to my punch script?

local player = game.Players.LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()

local right = Instance.new("Animation")

local left = Instance.new("Animation")

right.AnimationId = "http://www.roblox.com/Asset?ID=2984919647"

left.AnimationId = "http://www.roblox.com/Asset?ID=2987291306"

enable = true

local dmg = true

Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.KeyDown:Connect(function(Key)

if Key == "e" then

local anim = character:WaitForChild("Humanoid"):LoadAnimation(right)

if enable == true then

anim:Play()

wait(0.2)

end

elseif Key == "q" then

local anim = character:WaitForChild("Humanoid"):LoadAnimation(left)

if enable == true then

anim:Play()

wait(0.2)

end

end

end)

3 comments

0

this is not optimized for a damage snippet to be easily fitted

0

btw u can manually script the animation instead of adding it makes it more dynamic

0

I need this for it can be used on script builders( I dont know how to script an animation also)

1 answer

✓ Accepted answer

You'll need to use Remote Events to damage somebody but if you want it locally the script would look like this;

Code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local right = Instance.new("Animation")
local hitting = false --Added Variable To define if user is hitting someone or no
character["Right Arm"].Touched:Connect(function(hitter)
	if hitting then
		if hitter.Parent:FindFirstChild("Humanoid") then
local percentage = hitter.Parent.Humanoid.Health / hitter.Parent.Humanoid.MaxHealth
			local quarterHealth = (percentage / 4) * hitter.Parent.Humanoid.MaxHealth
			hitter.Parent.Humanoid:TakeDamage(quarterHealth)
		end
	end
end)
right.AnimationId = "http://www.roblox.com/Asset?ID=<YourAnimationId>"
enable = true
local dmg = true
Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.KeyDown:Connect(function(Key)
	if Key == "e" then
		local anim = character:WaitForChild("Humanoid"):LoadAnimation(right)
		if enable == true then
			hitting = true
			anim:Play()
			wait(0.5)
			hitting = false
		end
	end
end)

Hope this helped.

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