Any ideas on how this could fail?

local allplayers = game.Players:GetPlayers()
for i = 1, #allplayers do
	local oneplayer = allplayers[i]
	if oneplayer ~= nil and oneplayer:FindFirstChild("leaderstats") ~= nil then
		rewardplr(oneplayer)
	end
end

Apparently this failed, softlocking the game session. I’m learning scripting by myself with trial and error so I can make mistakes without noticing. Can anyone enlighten me? Also how could I prevent this failing?

No, I don’t have access to output since this was a bug report from a few hours ago. It’s probably a super rare thing too.

The only thing I can think of is someone leaving right as the script is firing the function but then “oneplayer ~= nil” is there for that…?

1 Like
if oneplayer ~= nil and oneplayer:FindFirstChild("leaderstats") ~= nil then

I think this is why its not working? have you tried removing it? i may be wrong

Actually, yeah, that seems very possible and the function can check for that. Alright, I’ll try this and hope it doesn’t happen ever again. This is a very rare bug report so I’ll leave this up just in case someone can pin-point the mistake. Thanks :slight_smile:

Just a tip, the ~= nil parts on both sides are actually not necessary.

1 Like

~= is fine I guess even tho not needed, but if it was failing it probably because of a spelling error on leader stats, could have made it a capital L not lower case