Putting Players in Tables

  1. What do you want to achieve? I’m trying to put all the players in game.Players to my table so then I can grab a boolvalue and do something with it. The thing is, since there’s obivously more than 1 player in the game I don’t know how to call them all but only check 1 by 1.

  2. What is the issue? Here’s my code.

game.Players.PlayerAdded:Connect(function(Player)
	local ShiftEndEvent = game.ReplicatedStorage.Events.ShiftEndEvent
	ShiftEndEvent:FireClient(Player)
	Player.Chatted:Connect(function(message)
		local AdminWhoUsedCMD = game.ReplicatedStorage.Values.AdminWhoUsedCMD
		if string.find(message, "!shiftstart") then
			if Player:GetRankInGroup(12556758) >= 8 then
				
			AdminWhoUsedCMD.Value = Player.Name
				
			local milisecond = 0
			local second = 0
			local minute = 0

			while wait(0.01) do
				if milisecond >= 60 then
					milisecond -= 60
					second += 1
				end
				if second >= 60 then
					second -= 60
					minute += 1
				end
				milisecond += 1
				end
							
			local MinuteValue = Instance.new("NumberValue", Player)
			MinuteValue.Name = "Minutes"
			MinuteValue.Value = minute
	end
			
			
		elseif string.find(message, "!shiftend") then
			local MinutesWorked = Player:FindFirstChild("Minutes")
			if Player:GetRankInGroup(12556758) >= 8 then
				local GrabWorkers = {}
				for i,v in pairs(game.Players:GetPlayers()) do
					local AllPlayers = i:Clone()
					table.insert(GrabWorkers, AllPlayers)
				end
				
				print(GrabWorkers)
			end
		end
	end)
end)

Could you not just do GrabWorkers = game.Players:GetPlayers()?

1 Like

Thank you, I just changed the value of GrabWorkers and removed the for loop, but how would I go about checking the value inside the player? The value is a boolvalue, if that helps.

It depends on the usage. If you want all bool Values to be affected, a for loop would suffice. However, you can’t directly access one person due to it being an array, however I doubt it’s being used for that purpose. It’d look something like such:

local tab = {} -- Table here
for _, v in pairs(tab) do
   v.BoolValue = false
end
1 Like