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

table not working?

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

✓ Accepted answer

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

1 comment

0

thank you

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