Title explains it all. I have player folders in ReplicatedStorage that are added when the player joins, these folders contain all of their data.
I also have a GUI in the bottom left corner of the screen that displays how many coins a player has, and the amount of coins are found in said playerFolder. I have made a simple script that updates the GUI when the coin amount updates.
local player = game.Players.LocalPlayer
local playerFolder = game.ReplicatedStorage.Players:WaitForChild(player.UserId) or game.ReplicatedStorage.Players[player.UserId]
script.Parent.Text = playerFolder.Coins.Value
playerFolder.Coins.Updated:Connect(function(value)
print("more coins")
script.Parent.Text = value
end)
An obvious issue is that this script runs the moment it loads into the client, so the player folder may not be there by the time the script starts and an error will be thrown, no biggie, I just add the condition game.ReplicatedStorage.Players:WaitForChild(player.UserId)
to ensure that if it hasn’t already loaded, it will be set once it loads. But this does not work, I am still given errors saying that the userId of the player (which is the name of the playerFolder) is not found in ReplicatedStorage when the script runs. Does the script not halt everything that happens until that child is added or detected? How do I fix this?