The code seems to be meant to update a health bar based on changes in a player’s health.
Here’s a modified version of the code with some assumptions:
local Player = game.Players.LocalPlayer
local Main = -- Reference to your main user interface
local function UpdateHealthBar()
local Humanoid = Player.Character and Player.Character:FindFirstChild("Humanoid")
if Humanoid then
Main.HealthBar.Health.Text = tostring(math.round(Humanoid.Health)) .. " | " .. Humanoid.MaxHealth
Main.HealthBar.Bar.Size = UDim2.new(Humanoid.Health / Humanoid.MaxHealth, 0, 1, 0)
end
end
local function HealthChanged(dmg)
UpdateHealthBar()
end
Player.CharacterAdded:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
Humanoid.HealthChanged:Connect(HealthChanged)
UpdateHealthBar()
end)
To add to the responses above, looking into math.floor() should point you into the right direction.
Note that math.floor() rounds decimal values down regardless of how they close to are to the next whole number. Depending on what you’re intending to do, math.ceil() can help you yield opposite results, i.e. rounding up to the next whole number.