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

How to make variable show up on BillboardGUI?

Asked by 5 years ago

Hey, i'm trying to make the variable "Pajama Power" show up on my BillboardGUI. Here's my code:

wait()

--//Base elements
local Character = script.Parent
local NameTag = script:FindFirstChild("NameTag")

local NameTagClone = NameTag:Clone()
NameTagClone.Parent = Character:FindFirstChild("Head")
NameTagClone.Adornee = Character:FindFirstChild("Head")
NameTagClone.Username.Text = Character.Name
NameTagClone.Level.Text = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Pajama Power").Value
NameTagClone.Enabled = true

However, when I start my game, The GUI just shows the default text I set up ("Lvl"), and I get this error in the output window: 19:43:09.018 - Workspace.567koala.Script:11: attempt to index field 'LocalPlayer' (a nil value)

Not sure if this helps or not, but my folders involving the BillboardGUI are as follows:

StarterCharacterScripts
    Script
        NameTag
            Border
            Level
            Username

And my script creating the leaderstats/Pajama Power variable (which is inside ServerScriptService) is as follows:

local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local level = Instance.new("IntValue")
    level.Name = "Pajama Power"
    level.Value = 1
    level.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(onPlayerJoin)

Any ideas on what i'm doing wrong?

1 answer

Log in to vote
0
Answered by
srimmbow 241 Moderation Voter
5 years ago
Edited 5 years ago

You can't use LocalPlayer in a server sided script. You should use the

GetPlayerFromCharacter()

function to get their player instead of using LocalPlayer.

Example:

wait()

--//Base elements
local Character = script.Parent
local NameTag = script:FindFirstChild("NameTag")

local NameTagClone = NameTag:Clone()
NameTagClone.Parent = Character:FindFirstChild("Head")
NameTagClone.Adornee = Character:FindFirstChild("Head")
NameTagClone.Username.Text = Character.Name
NameTagClone.Level.Text = game.Players:GetPlayerFromCharacter(Character):WaitForChild("leaderstats"):WaitForChild("Pajama Power").Value
NameTagClone.Enabled = true
Ad

Answer this question