Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Simple code acting weirdly, anyone encountered this before?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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
0
Thank you very much for the answer, I appreciate it a lot!! ROOBLOXJakob123 22 — 4y
Ad

Answer this question