Hey guys! I made an HP Bar and there aren’t any issues with it, but there is a slight problem. The HP text, it shows multiple numbers right after the HP! Like this for an example: “95.27479010249”. Is there any way to remove that?
local UI = script.Parent
local HPBar = UI["HP Bar"]
local KRBar = UI["KR Bar"]
local HPText = UI["Remaining Health"]
local Players = game.Players or game:GetService("Players")
local SetHPSize = false
print("Script active.")
local function GetHealth(Obj)
if Players:GetPlayerFromCharacter(Obj) then
local Character = Obj
local Client = UI.Parent:FindFirstAncestorOfClass("Player")
if Client and Character and Character:FindFirstChild("Humanoid", true) and Character.Name == Client.Name then
local Humanoid = Character.Humanoid
if Humanoid ~= nil then
local HP = Humanoid.Health
local MaxHP = Humanoid.MaxHealth
if SetHPSize == false then
SetHPSize = true
HPBar.Size = UDim2.new(HP / MaxHP * 0.267, 0, 0.099, 0)
KRBar.Position = HPBar.Position+UDim2.new(0.234, 0, 0, 0)
HPText.Text = tostring(math.floor(HP).."/"..math.floor(MaxHP))
print("Health script working.")
end
local Signal = Humanoid:GetPropertyChangedSignal("Health")
Signal:Connect(function()
if Humanoid.Health < HP or Humanoid.Health > HP then
local Hit = script.Hit:Clone()
Hit.Parent = Humanoid.Parent
Hit:Play()
Hit.Ended:Connect(function()
Hit:Remove()
end)
HP = Humanoid.Health
MaxHP = Humanoid.MaxHealth
HPBar.Size = UDim2.new(HP / MaxHP * 0.267, 0, 0.099, 0)
HPText.Text = tostring(HP.."/"..MaxHP)
print("Got hit. HP: "..HP)
end
end)
end
end
end
end
game.Workspace.ChildAdded:Connect(function(Child)
if Child.ClassName == "Model" then
GetHealth(Child)
end
end)
This is in a ServerScript. I tried everything I could to make it run on a LocalScript, but it just wouldn’t. If you know how to help me switch it over (which is optional just like helping me), I’d greatly appreciate it. Thanks, if you decide to help!