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

Sword does not do any damage. I used touched event with function. Please help?

So I have a function on my sword that makes it so when it touches someone, they are supposed to take damage, but nothing seems to happen. Also, the handle is the whole sword. Please help.

Here is my script:

local sword = script.Parent local handle = sword:FindFirstChild("Handle") local event = sword:FindFirstChild("RemoteEvent") local player = sword.Parent.Parent local humanoid = player:FindFirstChild("Humanoid")

handle.Touched:connect(function(hit) if player and humanoid and humanoid.Health > 0 then local hitHumanoid = hit.Parent:FindFirstChild("Humanoid") if hitHumanoid and hitHumanoid.Health > 0 then hitHumanoid:TakeDamage(50) end end end)

1 comment

0

please use code block lol

1 answer

✓ Accepted answer

Please put your code in a code block next time. Anyways this should help:

local sword = script.Parent
local handle = sword:WaitForChild("Handle") -- Wait instead so it doesn't error if it hasn't loaded it
local event = sword:WaitForChild("RemoteEvent") -- Same applies here
 
handle.Touched:connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and humanoid.Health > 0 then
		hitHumanoid:TakeDamage(50) end
	end
end)

Haven't tested this so it might not work. Cheers,

2 comments

0

The hitHumanoid part should've been humanoid but otherwise it worked. Thanks!

0

Your welcome!

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