local Players = game:GetService("Players")
local blackcolor = Color3.new(0, 0, 0)
local health = {}
function health.Setup(model)
local newHealthBar = script.HealthGui:Clone()
newHealthBar.Adornee = model:WaitForChild("Head")
newHealthBar.Parent = Players.LocalPlayer.PlayerGui
if model.Name == "Base" then
newHealthBar.MaxDistance = 100
newHealthBar.Size = UDim2.new(0, 200, 0, 20)
else
newHealthBar.MaxDistance = 30
newHealthBar.Size = UDim2.new(0, 100, 0, 20)
newHealthBar.Title.TextColor3 = blackcolor
end
health.UpdateHealth(newHealthBar, model)
model.Humanoid.HealthChanged:Connect(function()
health.UpdateHealth(newHealthBar, model)
end)
end
function health.UpdateHealth(gui, model)
local humanoid = model:WaitForChild("Humanoid")
if humanoid and gui then
local percent = humanoid.Health / humanoid.MaxHealth
gui.CurrentHealth.Size = UDim2.new(percent, 0, 1, 0)
if humanoid.Health <= 0 then
gui.Title.Text = model.Name .. ": Dead"
else
gui.Title.Text = model.Name .. " : " .. humanoid.Health .. "/" .. humanoid.MaxHealth
end
end
end
return health
Im making a tower defense game and this is supposde to be the script for the health of the base. It doesnt update when an enemy walks into the base and i dont know why. The output doesnt give me any errors. and im just stumped please help. if you need more info about this just ask