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

How to add a damage script on this function?

Im a newbie so i dont have an idea of how to add a damage script here. Need help. TY

local mouse = game.Players.LocalPlayer:GetMouse()
local canDamage = false

script.Parent.Equipped:Connect(function()
	local Wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)
	Wield:Play()
	
	mouse.Button1Down:Connect(function()
		local Wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)
		local Attack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Attack)
		Wield:Stop()
		Attack:Play()
	end)
		
	mouse.Button1Up:Connect(function(hit)
		--damage here
	end)

end)

5 comments

0

This is in a tool?

0

looks like a tool

0

sir you gotta explain what are you trying to make

0

Who are we damaging? what are you trying to make? Is this a tool? Expand

0

im trying to make a sword. sorry.

2 answers

✓ Accepted answer

This is how you damage people, i do not understand fully what you want, but this is my best trying to understand what you want, this will also not replicate to the server meaning nobody else including the target player will see the damage occur to them. I suggest remote events for doing that

Use this:

local mouse = game.Players.LocalPlayer:GetMouse()
local canDamage = false
local damageAmount = 20 -- modify this to whatever you want

script.Parent.Equipped:Connect(function()
    local Wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)
    Wield:Play()

    mouse.Button1Down:Connect(function()
        local Wield = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Wield)
        local Attack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Attack)
        Wield:Stop()
        Attack:Play()
    end)

    mouse.Button1Up:Connect(function(hit)
        local target = mouse.Target
	
	if target.Parent:FindFirstChild("Humanoid") then
		local charTarget = target.Parent

		charTarget.Humanoid:TakeDamage(damageAmount)
	end
    end)

end)

Simply use this script:

local human = hit.Parent:FindFirstChild("Humanoid")

if human then
	human.Health = human.Health - damageAmount
end

Hope this helped!

1 comment

0

Although it seems like a gear not Humanoid.

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