Am I being stupid or?

game.Players.PlayerAdded:Connect(function(plr)
	for i in pairs(data.sheets[1].data[1].rowData) do
		if data.sheets[1].data[1].rowData[i].values[1].formattedValue == 'AviaJxnny' then
			print(data.sheets[1].data[1].rowData[i].values[2].formattedValue)
		end
	end
end)

Am I being stupid or something because it isnt counting that the player is joining.

Maybe because you only have one Variable in the for loop

for i in pairs
to
for i,v in pairs

Is this excerpt a part of a server script?

No, it isn’t just tried that.

I even tried to do,

game.Players.PlayerAdded:Connect(function()
    print("hi")
end)

Is that a local or regular script?, you should run the code in a regular script

I’m not quite sure what’s causing the script to error - are you able to upload a repro file?

A repro file is a .rbxm file where you include all the items linked to the script’s malfunction.

unfortunately it has private api keys that run the db

Ah, that’s perfectly fine. Regarding the other script:

Was this the only block of code in the script, or was there other code above it? Excessive code and functions such as Instance:WaitForChild() can delay the script, which might have caused your scripts’ failure to print in time.

game.Players.PlayerAdded:Connect(function(plr)
	for i, element in pairs(data.sheets[1].data[1].rowData) do
		if element.values[1].formattedValue == 'AviaJxnny' then
			print(element.values[2].formattedValue)
		end
	end
end)

Is this the same as your code above right? and if you are making a search an efficient way its using while loop not for loop. Btw maybe you need to make a print debugging to find out the error that sometimes solve bug issues like that idk if you have previous code that generates your problem.

Using a for anything, anything2 in pairs(table) do is the correct way to loop through a table. I’m not sure why you’d use a while loop for that.

1 Like

It always counts if the player joins. To test this, run this:

game:GetService("Players").PlayerAdded:Connect(print)
-- prints the name of all new players who join

if it doesn’t work, that means you have something above it that’s yielding the thread.

1 Like

Because when while loop is used finds the data required and stop searching.
For loop keep searching even if the data is found already.

That doesn’t really make sense. You can just break a for loop once you’ve found what you’re looking for.

1 Like

Yep you can do that but while loop does it for you :wink: