Hello, I am changing the value of a text label with code so that it equals the number of coins that the player has, but the text label UI is not updating, even though I can print the .text of it and it displays its value.
local Players = game:GetService("Players") function onPlayerAdded(player) local Money = Instance.new("IntValue") Money.Name = "Coins" Money.Value = 166 game.StarterGui.ScreenGui.CoinAmount.Text = Money.Value print(game.StarterGui.ScreenGui.CoinAmount.Text) end --When a player joins, call the onPlayerAdded function Players.PlayerAdded:connect(onPlayerAdded) --Call onPlayerAdded for each player already in the game for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
The StarterGui is not what the player see's on their screen. What the player see's is apart of the PlayerGui. The PlayerGui is a folder pasted into each player when they join the server. The folder contains the default settings (unless disabled), like chat, ontop of what is contained in the StarterGui. Updating the StarterGui is only going to edit what players that join the server AFTER you update it see, therefore, you have to edit the player's PlayerGui. To get access to their playerGui, you have to do > game.Players.(player username).PlayerGui.(What you want to get access to) <
This is the new version of your code. Contact me if there are any errors.
local Players = game:GetService("Players") function onPlayerAdded(player) local Money = Instance.new("IntValue") Money.Name = "Coins" Money.Value = 166 if player.PlayerGui:FindFIrstChild("ScreenGui") then -- this line isn't needed. player.PlayerGui.**.ScreenGui.CoinAmount.Text = Money.Value end end --When a player joins, call the onPlayerAdded function Players.PlayerAdded:connect(onPlayerAdded) --Call onPlayerAdded for each player already in the game for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
What the player sees is not controlled through ScreenGui.
ScreenGui
: "Children of this object get cloned into a Player's PlayerGui when their character spawns."
local Players = game:GetService("Players") function onPlayerAdded(player) local Money = Instance.new("IntValue") Money.Name = "Coins" Money.Value = 166 game.StarterGui.ScreenGui.CoinAmount.Text = Money.Value --if a new player were to join, their screen would show 166 coins, because it is changed in StarterGui print(game.StarterGui.ScreenGui.CoinAmount.Text) end --When a player joins, call the onPlayerAdded function Players.PlayerAdded:connect(onPlayerAdded) --Call onPlayerAdded for each player already in the game for _,player in pairs(Players:GetPlayers()) do onPlayerAdded(player) end
See PlayerGui vs. StarterGui (wiki.roblox)