Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i get a player from a table and have a gui popup?

Asked by
CyzDev 26
4 years ago
Edited 4 years ago

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.

0
What's not working? Ziffixture 6913 — 4y
0
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 CyzDev 26 — 4y
0
You need to include the actual code. Ziffixture 6913 — 4y
0
I get that error when i attempt to do something like this "randomPlayerFromTable.PlayerGui.RandomGui.Frame.Visible = true" CyzDev 26 — 4y
View all comments (2 more)
0
Done CyzDev 26 — 4y
0
So can you find anything? CyzDev 26 — 4y

Answer this question