What to change with a player that counts as nil

I expected that player were nil, but i can’t thought what should i change to.
a[S] already player’s name, but it isn’t count so what should do?

local M = Instance.new("StringValue")
local o = game.Players.MaxPlayers
while wait(1) do
	for S = 1,o do
		game.ReplicatedStorage.Players:ClearAllChildren()
		local Am = M:Clone()
		local a = game.Players:GetChildren()
		Am.Value = a[S]
		print(a[S])
		print("r u working?")
		Am.Parent = game.ReplicatedStorage.Players
	end	
end
1 Like

I noticed a few issues with your script. First:

Am.Value = a[S]

Am is a string value but you’re trying to save a object to a string value by using the a[S] statement when it should be a[S].Name
Second:
game.Players.MaxPlayers shows how many players can join that server, not how many players are in the server at that moment so when there is one person in the server and the code inside the loop runs a second time S value is equal to 2 and when you try to index a[S] it tries to get the value from the table with the index of 2 which equals to nil because there is only one person in this server so in short you should rewrite your code like this:

local M = Instance.new("StringValue")
while wait(1) do
	local o = game.Players:GetChildren()
	for S = 1,#o do
		game.ReplicatedStorage.Players:ClearAllChildren()
		local Am = M:Clone()
		Am.Value = o[S].Name
		print(o[S])
		print("r u working?")
		Am.Parent = game.ReplicatedStorage.Players
	end	
end

Do you mean game.Players.NumPlayers in the “o” variable? Because game.Players.NumPlayers Counts how many players are in this server and its hidden for some reason

Yes because Roblox deprecated it.

Yes because making a feature deprecated doesn’t mean it’s broken or disabled but it’s better to use the alternative options rather than the deprecated feature itself.

Wait so that means LoadLibrary() Isnt disabled?

It is disabled, even the API reference itself says it’s disabled, not just deprecated.
What I’m saying is that deprecated doesn’t exactly mean it’s removed/disabled but there are better alternatives to use rather than the deprecated feature.


https://developer.roblox.com/en-us/api-reference/lua-docs/Roblox-Globals

2020-09-12 21_22_00-Window

That setting has nothing to do with the code you provided.
Edit: I just realized that you posted that under my LoadLibrary post. Though I have no idea why you sent that considering that has nothing to do with LoadLibrary or anything.

also i found a issue in your fixed script
o[s] is a children that got by a name, so o[s] is becoming name of a children or maybe not :confused:

Am.Value = o[S].Name

In my code o is an array of player objects, not player names so you have to use o[S].Name to get the name of the players.