I want to get a random player from a table and have a GUI popup for that random player
example:
table.insert(playersPlaying,plr.UserId)
local randomPlayerFromTable = playersPlaying[math.random(1,#playersPlaying)]
randomPlayerFromTable.PlayerGui.RandomGui.Frame.TextLabel.Visible = true
How would I make this possible?
Any help is appreciated thanks.
edit: Actual code
for i,player in pairs(game.Players:GetPlayers()) do -------
local char = player.Character or player.CharacterAdded:wait()
if char then
local randomSpawns = map.Spawns:GetChildren()[Random.new():NextInteger(1,#map.Spawns:GetChildren())]
if cachedSpawns[randomSpawns] then
repeat randomSpawns = map.Spawns:GetChildren()[Random.new():NextInteger(1,#map.Spawns:GetChildren())] wait() until not cachedSpawns[randomSpawns]
end
table.insert(playersPlaying,player.UserId)
print(player.Name)
cachedSpawns[randomSpawns] = true
--teleporting players to spawn location
for a,b in pairs(playersPlaying) do
char.HumanoidRootPart.CFrame = (randomSpawns.CFrame * CFrame.new(0,2.25,0))
end
local inGame = false
local status = Game.Stats.Status
local gameTime = Settings.gameTimeLimit
end
end
local status = Game.Stats.Status
local gameTime = Settings.gameData.gameTimeLimit
local murdererWeapon = game.ServerStorage.Weapons.Knifes.Knife
local plrs = game.Players
local innocents = {}
while wait() do
inGame = true
repeat
gameTime = gameTime - 1
status.Value = gameTime.." "..((gameTime == 1 and "Second") or "Seconds").." left."
wait(1)
until gameTime == 0
break
end
local rgbMurderer = {161, 16, 18}
local rgbPychic = {132, 0, 198}
local rgbInnocent = {0, 184, 0}
local theChosenOne = playersPlaying[math.random(1,#playersPlaying)]
theChosenOne.PlayerGui.Role.Main.Visible = true -- this is where I get the error
Excuse the messy code.

6 comments
What's not working?
Having the guis popup. I get this error "attempt to index nil with 'Role'" or "attempt to index number with 'PlayerGui'" Role is a gui that shows that players role
You need to include the actual code.
I get that error when i attempt to do something like this "randomPlayerFromTable.PlayerGui.RandomGui.Frame.Visible = true"
Done
So can you find anything?