Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this work on studio but not actual game?

local StarterGui = game:GetService('StarterGui')
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)


local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

local mainframe = script.Parent.Main
local hpBar = mainframe.Health
local playerName = mainframe.PlayerName
local gui = script.Parent
local image = mainframe.PlayerImage

playerName.Text = player.Name
image.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username=".. player.Name

humanoid.HealthChanged:connect(function()
	local hpMath = humanoid.Health / humanoid.MaxHealth
	hpBar.Size = UDim2.new(hpMath,0,0.25,0)
end)

None of it happens. I don't know why.

Thanks in advance!

1 answer

✓ Accepted answer

Is this in a local script?

  • If not, you can't access LocalPlayer through a server script.

When going down the hierarchy, try using ":WaitForChild()". For example:

local humanoid = character:WaitForChild("Humanoid")

2 comments

0

Yeah it is a localscript

0

Nevermind I fixed it

This discussion is preserved as it was. New answers, comments, and votes are closed.