Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why dose this code only work on Studio?

Asked by 8 years ago

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)
1
Make sure this is in a LocalScript ItsMeKlc 235 — 8y
0
It is in the local script Zeckrahm 0 — 8y
0
Is it in a localscript that is inside StarterPlayerScripts or StarterGui? Validark 1580 — 8y
0
Its in StarterGui Zeckrahm 0 — 8y
0
Any errors? I would try waiting for the frame using waitforchild. Also why do you have two variables for the same thing? "Frame" is getting the parent of the script and so is "ScreenGui". Scriptecx 124 — 8y

1 answer

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
8 years ago

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.

Ad

Answer this question