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)
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,