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
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
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 Otherwise they’ll return back as nil if they’re different values or not found
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?
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.)