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

table not working?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
wait(1)
local admins = {
    "theCJarmy7",
    "Player1"
}

for i,v in pairs(admins) do
    if v.Name == game.Players.LocalPlayer.Name then
        print(v.Name.." has entered the game")
    else print("noooo")
        print(game.Players.LocalPlayer.Name)
    end
end

the output looks like this:

noooo

Player1

noooo

Player1

it should be working, i dont see any reason why it shouldn't be print: Player1 has enetered the game

1 answer

Log in to vote
1
Answered by 8 years ago

The reason why you're getting "noooo" is because you're looping through a table that as two things, so first you check to see if the current player is "theCJarmy7" and then you print. Right after that, it checks to see if the current player is also "Player1", you cannot be Player1 and theCJarmy7 at the same time so you'll get both prints.

wait(1)
local admins = {
    "theCJarmy7",
    "Player1"
}

for i,v in pairs(admins) do
    if game.Players.LocalPlayer.Name == v then -- v is a string, so you don't need .name, btw.
        print(v.Name.." has entered the game") -- Prints if the player is an admin
    elseif game.Players.LocalPlayer.Name ~= v then
     print("noooo")
        print(game.Players.LocalPlayer.Name) -- These will print if the player is not an admin, it should print each time their name is not on the list
    end
end
0
thank you theCJarmy7 1293 — 8y
Ad

Answer this question