Else not working

so I made a product that when bought, everyone has to get to the rocket, or else they die. ‘winners’ is the table of people who make it on time. if you win, it prints ‘dude7271 has won’ but if you don’t, it prints nothing.

local function winnerCheck()
    for i,v in pairs(game.Players:GetPlayers()) do
	    for i2,v2 in pairs(winners) do
	    	local player = table.find(winners, v.Name)
	    	if player == nil then
	   	    	print(v.Name .. " Has lost")
	     	elseif player then
	   		    print(v.Name .. " Has Won")
	       	end
        end
    end
end

I can’t seem to find the problem. thanks

1 Like

It’s just else not elseif that’s the problem

1 Like

what do you mean???

1 Like

What I said lol… elseif is used as the 2nd else statement not first I believe, you need an “else” statement before it can become an “elseif”

1 Like

Hmmm, so, there are a few problems in this. Firstly, you are already declaring that the player value is definitely there. Try this code and tell me if it works, (sorry if it’s not formatted correctly, I’m on mobile)

if table.find(winners, v.Name) then
print(v.Name…” has won”)
else
print(v.Name…” has lost”)
end

Hope this helps!

1 Like

okay, I’ll try that. thank you

1 Like

I already stated this above when you asked what I meant

1 Like

sorry i did not get what you meant

1 Like

Bit confusing, perhaps try this?

local function winnerCheck()
    for i,v in pairs(game.Players:GetPlayers()) do
	    for i2,v2 in pairs(winners) do
	    	local player = table.find(winners, v.Name)
	    	if player then
	   	    	print(v.Name .. " has won")
	     	else
	   		    print(v.Name .. " has lost")
	       	end
        end
    end
end

When trying to search for your winners table, you should have string values the same as your v.Name :thinking: Otherwise they’ll return back as nil if they’re different values or not found

1 Like

Just remove the inner for (and its end.) The else / elseif thing is a non-issue.

unfortunately no. I also tried

local player = table.find(winners, v2.name)

I just realized that you’re looping through the table twice-

local function winnerCheck()
    print(winners)
    for i,v in pairs(game.Players:GetPlayers()) do
        print(v)
	    local Winner = table.find(winners, v.Name)
	    if Winner then
	   	    print(v.Name .. " has won")
	    else
	        print(v.Name .. " has lost")
	    end
    end
end

Are you sure that you’re inserting the winners table properly whenever they win?

that works. thanks. I see why now lol.

yeah @Club_Moo made me realize that too, thanks for your help though!

So just for completeness–I don’t know if you want to, but if you want to mention
players that have left the game that are winners (if you allow that) you’ll need to
do some extra work (getting players in winners that are no longer in the game.)

oh, yes. thanks for pointing that out.