I am looking for someone who is able to help me make a script that selects a random player from the player list. I also want the script to get their avatar and username.
I made a GUI that has the following included: SurfaceGUI, textlabel, another textlabel, frame, ImageLabel.
One of the text label should be for displaying the user's name, the other one for the dialogue. The ImageLabel will be for showing the random player's avatar.
Can this be done, if so, please help. Thanks!
This is for a camping game, on roblox.
You can add in a script somewhere that has a function that runs when the player joined. That function will create a StringValue. The name of the StringValue will be 1 for the first player that joined, 2 for the second that joined, etc. The Value of the StringValue will be the joined player's name. That StringValue's parent will be the Workspace.
If you want to randomly choose a player to say a dialog you can now use the math.random option, cuz math.random only uses numbers , but you already named the StringValues in workspace with numbers. You can do this to randomly choose a player to say a dialog:
local chosenPlayerValue = math.random(1,#game.Players:GetChildren) local chosenPlayer = game.Workspace:WaitForChild(chosenPlayer) local playerName = chosenPlayer.Name > ADD WHATEVER YOU WANNA DO
Hope this helped!
local rng=math.random(1,#game.Players:GetChildren()) local pl; local gui=your gui here for i,v in pairs(game.Players:GetChildren()) do if i==rng then pl=v end end gui.TextLabel.Text=pl.Name gui.ImageLabel.Image=https://www.roblox.com/bust-thumbnail/image?userId=..pl.UserId..&width=420&height=420&format=png
This should work, not tested it. If it does: please accept this answer. Thank you!
Closed as Not Constructive by cmgtotalyawesome, royaltoe, hiimgoodpack, ForeverBrown, maumaumaumaumaumua, and User#5423
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?