So I'm making an object that will destroy itself when its health hits zero. It has a humanoid in it and it is able to take damage from a gun that I shoot at it with I'm trying to get the script to pull the health value so it knows when to destroy, but for some reason the only value it can pull is the health that the humanoid has at the start
local LaserPointer = script.Parent
local CanAttack = true
humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
while wait() do
local bulletRay = Ray.new(LaserPointer.Position, LaserPointer.CFrame.LookVector * 100)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(bulletRay, {LaserPointer})
if hit then
if hit.Parent:FindFirstChild("Humanoid") and CanAttack == true then
CanAttack = false
local PlayerHit = hit.Parent:FindFirstChild("Humanoid")
PlayerHit.Health = PlayerHit.Health - 25
print(PlayerHit.Health)
LaserPointer.Parent:Destroy()
end
end
if humanoid then
if humanoid.Health < 0 then
--print("What what")
CanAttack = false
LaserPointer.Parent:Destroy()
end
print(humanoid.Health)
end
end
It can detect the humanoid, and it's detecting the correct humanoid, but it seems to have trouble pulling the health past the initial value. Any help here?
