Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if someone is in a table then?

Asked by
L43Q 48
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.

0
One question, what's break? L43Q 48 — 9y
0
Oh yeah, that was what I was looking for :P. L43Q 48 — 9y
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. User#9643 0 — 9y
0
Okie dokes, thanks. L43Q 48 — 9y
Ad

Answer this question