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

Why does this work on studio but not actual game?

Asked by
FizTech 15
8 years ago
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

Log in to vote
0
Answered by 8 years ago

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")
0
Yeah it is a localscript FizTech 15 — 8y
0
Nevermind I fixed it FizTech 15 — 8y
Ad

Answer this question