So I'm trying out scripts in a game, but this script that's supposed to print out a specific value, (berryID.Value) only works 50% of the time, even with no changes to the script (or any script) between testing. When it doesn't work, it outputs "playerStats is not a valid member of Player" even though it clearly is. Anyways, here's the script, hope someone can help:
`
game.Players.PlayerAdded:Connect(function(player)
local Be = player.playerStats.berryID while true do wait(1) print(Be.Value) end
end)`
Scripts are not guaranteed to run in a specific order. If you make your playerStats in a different script when your player is added and need to obtain it in another you have to make use of WaitForChild.
local Be = player:WaitForChild("playerStats").berryID