Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Simple code acting weirdly, anyone encountered this before?

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)`

1 answer

✓ Accepted answer

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

1 comment

0

Thank you very much for the answer, I appreciate it a lot!!

This discussion is preserved as it was. New answers, comments, and votes are closed.