✓ Accepted answer
Well, first of all, (almost) every :Connect(function() returns a argument in "function(arg1)" (which of, arg1 is the argument it returns.). In this case, the :Connect(function(arg1) returns the part being hit. (:Connect(function(partBeingHit)). So, knowing that, you can do:
local damage = script.Parent.Configuration.Damage.Value
script.Parent.Part.Touched:Connect(function(partBeingHit)
local hum = partBeingHit.Parent:FindFirstChild("Humanoid")
if hum then
hum.Health = - damage
end
end)
But wait, theres a problem here: A error occours in line 6. Well, the maths here are wroten wrong.
if hum then
hum.Health = - damage
end
the correct way would be:
if hum then
hum.Health = hum.Health - damage
end
that works.
heres the fixed version, without all the explaining:
local damage = script.Parent.Configuration.Damage.Value
script.Parent.Part.Touched:Connect(function(partBeingHit)
local hum = partBeingHit.Parent:FindFirstChild("Humanoid")
if hum then
hum.Health = hum.Health - damage
end
end)
Hope that helped.
2 comments
umm where is this script located?
In the tool itself