Why is my table script not working?

Why will my script not work? It does not print out anything from what I put.

local Players = {}

game.ReplicatedStorage.HostStuff.AddPlayer.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup(6559630) >= 20 then
		if not table.find(Players, plr.Name) then
			print("Player is not in host system but now is.")
			table.insert(Players, plr.Name)
		else
			print("Player is already in the host system")
		end
	end
end)
1 Like

Is the :GetRankInGroup() part working fine? If it is then try this:

local Players = {}

game.ReplicatedStorage.HostStuff.AddPlayer.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup(6559630) >= 20 then
		if not Players[plr]  then
			print("Player is not in host system but now is.")
			Players[plr] = true
		else
			print("Player is already in the host system")
		end
	end
end)
2 Likes

That fixes it, now I am trying to do this but have an error:

local Players = {}

game.ReplicatedStorage.HostStuff.HostAddPlayer.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup(6559630) >= 20 then
		if not Players[plr]  then
			print("Player is not in host system but now is.")
			for i, v in pairs(game.Players:GetChildren()) do
				local clone = game.ServerStorage.Name:Clone()
				clone.Parent = v.PlayerGui.SurfaceGui.ListDown
				clone.Text = plr.Name
			end
			Players[plr] = true
		else
			print("Player is already in the host system")
		end
	end
end)

Error:
image

1 Like

Is this the full script? Also what type of object is clone?

1 Like

it is.

this is what it is cloneing and then puting it into a surface UI in the player gui

image

1 Like

You’re saving an instance inside of a table, so it would be:

game.ReplicatedStorage.HostStuff.HostAddPlayer.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup(6559630) >= 20 then
		if not Players[plr.Name]  then
			print("Player is not in host system but now is.")
			for i, v in pairs(game.Players:GetPlayers()) do
				local clone = game.ServerStorage.Name:Clone()
				clone.Parent = v.PlayerGui.SurfaceGui.ListDown
				clone.Text = plr.Name
			end
			Players[plr.Name] = true
		else
			print("Player is already in the host system")
		end
	end
end)

I recommend using :WaitForChild() or :FindFirstChild(), so do this: v:FindFirstChild("PlayerGui"):FindFirstChild("SurfaceGui"):WaitForChild("ListDown")

1 Like

I get this error with ur script still

image

That should not affect anything with the error i am now geting

1 Like

I know this is off-topic but I would put the player’s UserId in the table instead of their name…

Why? It does not really matter because when the player leaves the game they will be removed from the table anyways.

1 Like

The error is because you have it called Name, which is also a property. Change the name to something else.

1 Like

This ^, change the Name Text GUI name to NameGUI.