#BillboardGui to display a player's leaderstat value
34 messages · Page 1 of 1 (latest)
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)
** You are now Level 2! **
@tribal wagon
Is the function in the char added function?
I can’t tell
You’ll need to make it global
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
It’s a local function - it can only be called on its own and under scopes
yeah and its being called in the same scope
** You are now Level 6! **
wdym
wdym? It's defined in the character added function, and its only called twice, both of which are also in the character added function
@small lodge are you sure that :GetPropertyChangedSingal is the correct event to be looking for?
i meant the script looks like it should work
well im looking towards the text updating when the value of the leaderstat does too
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
i'll try
@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
Any luck?
np
np