If you do say that It only doesn’t change on load up then it’s probably due to the script loading after the player instances have been loaded and registered the first values. In this case you might want to do this :
local player = game.Players.LocalPlayer
local function changeCoinsText(val)
CoinsDisplay.Text = val
end
player:WaitForChild(“Values”):WaitForChild(“Coins”).Changed:Connect(changeCoinsText)
changeCoinsDisplay()
I am currently on mobile so might have skipped some variables like coinsdisplay or gems but you probs understand what I mean.
game.Players.PlayerAdded:Connect(function(player)
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Parent = player
--pretend read from data store
coins.Value = 100
task.wait(10) --some game play happens
--we get more coins
coins.Value = 200
end)
On Client
local player = game.Players.LocalPlayer
local coins = player:WaitForChild("Coins")
--setup our changed event
coins.Changed:Connect(function()
print("set changed coins",coins.Value)
end)
--init our gui to show what is in coins NOW
print("set starting coins ",coins.Value)
Player.Values.Coins.Changed:Connect(function(value)
print("hi")
CoinsDisplay.Text = Player.Values.Coins.Value
end)
--init the gui with the current value of Coins
CoinsDisplay.Text = Player.Values.Coins.Value
And just to make something clear about the .CharacterAdded on local script, it does work, but it has to be under PlayerScripts
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Connect(function()
print("Character Added")
end)
will output
EDIT It would probably also work under the GUI, as long as the GUI is created when the player loads and not when the character loads. There is an option to reset the gui or not when the character resets, this would need to be set to not reset the gui when the character resets.
Both have pros and cons but for instances like StringValue and IntValue, Changed even is fired when the Instance’s value is changed. Using Changed could be better for IntValue