A Simple Player Value

Hello! So in this server script, I want it to make it where each player has their value inside of a folder in ServerStorage unless the player has a value inside a player called, “OutOfGame”. The value will be in another script, but I won’t show it because it is off topic. Here is the script:

local function peopleingame()
	local playerfolder = game.ServerStorage.PlayerInGame
	for i, v in pairs(game.Players:GetPlayers()) do
		if not v:FindFirstChild("OutOfGame") then
			local playervalue = Instance.new("ObjectValue")
			playervalue.Name = v
		end
	end
end	

So I always feel like it is only going to print one value, and there is going to be in error going into my output, but if you have any ideas, please comment below!

1 Like

The Script looks to be all fine, though there is just two things:

  1. playervalue doesn’t have it’s Parent assigned to, I’m guessing you want to Parent it to PlayerInGame.
  2. ipairs() should be used when iterating through arrays due to the optimisation it gives.

So your saying, if I changed pairs to ipairs, it would change it to many (or the maximum player count) of values?

I never said that nor do I get what you’re meaning.
pairs() iterates over every index in a table, unordered.
ipairs() iterates over every index which is a number, in order.

Error:

  17:34:27.091 - ServerScriptService.MainScript:36: bad argument #3 to 'Name' (string expected, got Object)

script:

local function peopleingame()
	local playerfolder = game.ServerStorage.PlayerInGame
	for i, v in ipairs(game.Players:GetPlayers()) do
		if not v:FindFirstChild("OutOfGame") then
			local playervalue = Instance.new("ObjectValue")
			playervalue.Name = v
			playervalue.Parent = playerfolder
			print(playervalue.Name)
		end
	end
end	

Name is a string, and you’re providing v (a Player).
Did you mean to either set the .Value of the ObjectValue or set the Name to v.Name?

I am trying to make it where the value’s name is the player’s name.

Therefore, you should be setting it to v.Name

I am going to be testing it out…

So, it did work, but the printed word turned bold and red.