#BillboardGui to display a player's leaderstat value

34 messages · Page 1 of 1 (latest)

small lodge
#

so i wrote a script to make a billboard gui that does the thing in the title, and it doesn't do that at all. Script is gonna be down below

tribal wagon
small lodge
#

wait

#
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)

        local billboardGui = Instance.new("BillboardGui")
        billboardGui.Name = "PlayerStatsDisplay"
        billboardGui.Adornee = character:WaitForChild("Head")
        billboardGui.Size = UDim2.new(2, 0, 1, 0)
        billboardGui.StudsOffset = Vector3.new(0, 2, 0) 
        billboardGui.Parent = character

        local textLabel = Instance.new("Time")
        textLabel.Size = UDim2.new(1, 0, 1, 0)
        textLabel.BackgroundTransparency = 1
        textLabel.TextScaled = true
        textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
        textLabel.Parent = billboardGui

        local function updateText()
            local time = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Time")
            if time then
                textLabel.Text = tostring(time.Value)
            end
        end

        player.leaderstats.Time:GetPropertyChangedSignal("Value"):Connect(updateText)

        updateText()
    end)
end)
woven raptorBOT
#

studio** You are now Level 2! **studio

small lodge
#

@tribal wagon

dawn shuttle
#

Is the function in the char added function?

#

I can’t tell

#

You’ll need to make it global

paper summit
#

Why would that make a difference? It appears to only be called in the playerAdded event

#

id agree its not good form but it should work

dawn shuttle
#

It’s a local function - it can only be called on its own and under scopes

paper summit
#

yeah and its being called in the same scope

woven raptorBOT
#

studio** You are now Level 6! **studio

dawn shuttle
#

Ok I couldn’t tell

#

But it looks function to me

small lodge
paper summit
#

@small lodge are you sure that :GetPropertyChangedSingal is the correct event to be looking for?

dawn shuttle
small lodge
paper summit
#

This is from the docmentation:

#

ValueBase objects, such as IntValue and StringValue, use a modified Changed event that fires with the contents of their Value property. As such, this method provides a way to detect changes in other properties of those objects.

#

I think you should use changed instead of get property chnaged

small lodge
#

i'll try

dawn shuttle
#

@small lodge instead of having a character added in the player function, i would reccomend something like this:

local function updateText(player, newValue) --use the passed new value to your advantage, instead of reassigning
  textLabel.Text = ...
end


playerAdded:Connect(function(player)
  local character = player.Character or player.CharacterAdded:Wait() --yields exec until character is loaded
  
  local bbgui = ...
  
  propertyChanged:Connect(function(val) updateText(player, val) end)
end)
#

this makes it easier to read and less billions of function calls

paper summit
small lodge
#

yuhhh

#

done

#

tyssm

#

to both of you

paper summit
#

np

dawn shuttle
#

np