Need Help With Script

How would I make it so a random player will get a certain GUI? Below is the code I have so far. Help would be appreciated!

wait(6)

while true do
	p = game.Players:GetChildren()
	randplayer = p[math.random(#p)]
	randplayer.TeamColor = BrickColor.new("Camo")
	randplayer.Character:BreakJoints() 
	randplayer.Character.PlayerGui.Choice.Main.Visible = true
end

In your code there isn’t any waits in the true loop so the game will have a script timeout / error. Controlling the PlayerGui on the server is never a good practice. You should controll the PlayerGui on the client, you could send remote functions or remote events from the server to the client to make the Gui invisible.

I don’t know how to do that :pensive:

You can put a RemoteEvent in ReplicatedStorage and have the server fire the function to the client every 10 seconds like this

wait(6)
local RemoteEvent = --your remote event

while wait(10) do
	p = game.Players:GetChildren()
	randplayer = p[math.random(1, #p)]
	randplayer.TeamColor = BrickColor.new("Camo")
	randplayer.Character:BreakJoints() 
	RemoteEvent:FireClient(randplayer) --fires the event
end
--in a localscript in StartGui
wait(5)
local RemoteEvent = --your remote event
local PlayerGui = script.Parent

RemoteEvent.OnClientEvent:Connect(function()
PlayerGui.Choice.Main.Visible = true
end)

You can add some print() if you want to test if it works.

you could make a table list wich contain your guis and the with math.random chose a random gui
like so:

guis = {gui1, gui2, gui3}

local gui = guis[math.random(1, #guis)]

Well what I want to do is to give a gui to a random player not a random gui.

yeah srry i mis understooth the question

with this you would choose a random player from the game

local players = {}

for i,v in pairs(game.Players:GetChildren()) do
    table.insert(players, #players, v)
end

randomPlayer = players[math.random(1, #players)]
local RemoteEvent = game.ReplicatedStorage.Gui
while wait(10) do
	p = game.Players:GetChildren()
	randplayer = p[math.random(#p)]
	randplayer.TeamColor = BrickColor.new("Camo")
	randplayer.Character:BreakJoints() 
	RemoteEvent:FireClient(randplayer)

end

like this? I named the remoteEvent Gui

Yea you can do that if you want to.

one problem the local script for “local PlayerGui = script.Parent” is coming up with an error

Did you put the local script in the StarterGui? Make sure PlayerGui.Choice.Main exists and it isn’t nil.

It was a weird roblox glitch it works now! Thank YOu!