Hi there. So I'm wondering why I cannot print a variable after it has been in a repeat loop. Take a look at this script here:
wait(20) local playerlogger = {} for i, player in pairs(game.Players:GetPlayers()) do table.insert(playerlogger, player.Name) print(table.concat(playerlogger, " ")) end local playerPicker1 = math.random(1,#game.Players:GetPlayers()) local playerPicker2 = math.random(1,#game.Players:GetPlayers()) print(playerlogger[playerPicker1]) print(playerlogger[playerPicker2]) if playerPicker1 ~= playerPicker2 then print("player 1 is not player 2") else repeat local playerPickerNewSelection = math.random(1,#game.Players:GetPlayers()) until playerPickerNewSelection ~= playerPicker2 print(playerlogger[playerPickerNewSelection]) print("player 1 is not player 2(after new selection") end
Basically, it will get 2 random players from the playerlogger
table (playerPicker1
and playerPicker2
) and check if the two picked players are the same player. If it is, then it will keep making a new variable (playerPickerNewSelection
) until this new variable isn't an already selected player. The problem is that I can't seem to print(playerlogger[playerPickerNewSelection])
, which I would need to print in order to see if the new selected player isn't the same one.
I would appreciate any help I receive, and thank you for reading this question.
I think this will work? Maybe, its completely untested so let me know.
wait(20) local playerlogger = {} for i, player in pairs(game.Players:GetPlayers()) do table.insert(playerlogger, player.Name) print(table.concat(playerlogger, " ")) end local playerPicker1 = math.random(1,#game.Players:GetPlayers()) local playerPicker2 = math.random(1,#game.Players:GetPlayers()) print(playerlogger[playerPicker1]) print(playerlogger[playerPicker2]) while playerPicker1 == playerPicker2 do playerPicker2 = math.random(1,#game.Players:GetPlayers()) print("player 1 is player 2, trying again") wait(.1) end print(playerlogger[playerPicker1]) print(playerlogger[playerPicker2]) print("player 1 is not player 2")
The table seems to work fine, I don't fully know whats the issue, but I fixed it. ~~~~~~~~~~~~~~~~~ wait(20)
local playerlogger = {}
for i, player in pairs(game.Players:GetPlayers()) do table.insert(playerlogger, player.Name) print(table.concat(playerlogger, " ")) end local playerPicker1 = math.random(1,#game.Players:GetPlayers()) local playerPicker2 = math.random(1,#game.Players:GetPlayers()) local playerPickerNewSelection = math.random(1,#game.Players:GetPlayers()) print(playerlogger[playerPicker1]) print(playerlogger[playerPicker2]) if playerPicker1 ~= playerPicker2 then print("player 1 is not player 2") else repeat local playerPickerNewSelection = math.random(1,#game.Players:GetPlayers()) until playerPickerNewSelection ~= playerPicker2 print(playerlogger[playerPickerNewSelection]) print("player 1 is not player 2(after new selection") end ~~~~~~~~~~~~~~~~~ I tested it and it worked like I think it should but if not let me know.