Getting character from a player in a table

for _, v in pairs(Players:GetPlayers()) do
	table.insert(Settings.ALL_PLAYERS, v)
end
	
Settings.ACTIVE_PLAYERS = Settings.ALL_PLAYERS

-- Seperate module
for _, player in pairs(Settings.ACTIVE_PLAYERS) do
	print(player)
	local Character = player:FindFirstChild('Character')
	print(Character) -- Prints nil
	if Character then
		Character.PrimaryPart.Anchored = false
	end
end

Can the character of a player not be found if that player is stored inside a table?

1 Like

Since you are using FindFirstChild, you are trying to look for an object inside the player called “Character”, this will not work as Character is a property of the player and not a child. You should simply reference Player.Character and have an if statement to check if it is not nil.

local Character = Player.Character
if Character then
    Character.PrimaryPart.Anchored = false
end
5 Likes