Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

if someone is in a table then?

Basically, if someone is in a table (called hosts), I want to do something... is it related to this?

		for i,v in pairs(hosts) do

		end

How would I do it?

If you can't understand, then...

		for i,v in pairs(hosts) do
			if (player is in a table called hosts) then

			end
		end

OBVIOUSLY , if player is in a table called hosts then isn't correct, but I need help with it. I hope you guys understand D;.

UPDATE: I may've worked it out, but I don't think so. Is this correct:

		for i,v in pairs(hosts) do
			if player.Name == v then
				
			end
		end

1 answer

✓ Accepted answer

I'm assuming that you want to check if a player is in the table called hosts and to check that it would be simple:

local hosts = {"imaginaryjeffery321"}
for i,v in pairs(hosts) do
	for i2,p in pairs(game.Players:GetPlayers()) do --This will loop through all the player's currently in the game
		if p.Name == v then --p.Name because the value in hosts is a string value and not a player object.
			--Whatever stuff you want, host priveleges presumably.
			break
		end
	end
end

However, if you want to check if a player is in that table when they join. That'll be like so:

local hosts = {"imaginaryjeffery321"}
game.Players.PlayerAdded:connect(function(ply) --This is called whenever a player is added.
	for i,v in pairs(hosts) do
		if ply.Name == v then --p.Name because the value in hosts is a string value and not a player object.
			--Host stuff
			break
		end
	end
end)

Hope this is what you were looking for.

4 comments

0

One question, what's break?

0

Oh yeah, that was what I was looking for :P.

0

break just means that it exit outs of the current loop. I use it because you've already found what you're looking for and so there's no point continuing to loop through the rest of the values.

0

Okie dokes, thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.