I made a custom Health Bar. I use the same code in the Roblox Wiki. It did work, but only on studio. Why?
local player = game.Players.LocalPlayer local Frame = script.Parent local ScreenGui = script.Parent Frame.PlayerName.Text = player.Name local healthBar = ScreenGui.HealthContainer.HealthBar player.CharacterAdded:connect(function(character) local humanoid = character:WaitForChild('Humanoid') humanoid.HealthChanged:connect(function(health) local healthPercentage = health / character.Humanoid.MaxHealth healthBar.Size = UDim2.new(healthPercentage, 0, 1, 0) end) end) game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
At the very beginning of your script, put a wait()
.
The game client has to load more than just Play Solo mode in Studio, so you need to give it some time to load everything properly.
If wait()
doesn't work, put a larger waiting time value in it, such as wait(0.5)
or however long you feel it should be for the game to start the script.