Almost done with my sword, how do I make it conflict damage?

My script (so far):

script.Parent.Activated:Connect(function()
	
	local anim = script.Animation
	local humanoid = script.Parent.Parent.Humanoid
	
	local animTrack  = humanoid:LoadAnimation(anim)
	animTrack:Play()
	
	script.one:Play()
	
	script.Disabled = true
	
	wait(1)
	script.Disabled = false
	

end)

how do I make the sword do damage once it hits another player?

In simple terms, you will need to communicate with a server script (preferrably within the tool) via a RemoteEvent, which will inflict the damage on the target’s Humanoid on the server.

I really wouldn’t reccomend doing this, as an exploiter could just spam the RemoteEvent, dealing damage to them immediately the second they get in range with them, basically ruining the entire game.

A better way would be to perhaps use Region3’s/ GetPartsInPart
Or use the default Touched method (unreliable, client can exploit but still the easiest)

local Tool = script.Parent
local MChar
local Handle = Tool:WaitForChild("Handle")

Tool.Activated:Connect(function(...)
	MChar = Tool.Parent
	local Got = workspace:GetPartsInPart(Handle)
	for _, v in ipairs(Got) do
		if v.Parent then
			local Char = v.Parent
			local Humanoid = Char:FindFirstChildWhichIsA("Humanoid")
			if v:IsA("BasePart") and Humanoid and Humanoid.Parent ~= MChar then
				Humanoid:TakeDamage(10)
				break
			end
		end
	end
end)

Untested code, but that should be a good example.
Edit: Used a stupid method to prevent self damage, look into OverlapParams to get a better fix than what I did : /

1 Like

Edit; this deals damage to yourself, whoops let me edit…

1 Like

I copied the script and it worked, I still take damage though. How can I fix that?

Add Char ~= MChar on the if statement where the damager happends

I use raycast(extra characters)

Use this code instead; it’s the right one.