Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a script that is able to get a random players avatar and name? (Camping Game)

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.

3 comments

0

Can you give an example of your script?

0

Please post your script.

0

I dont have the scripts.

2 answers

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!

1 comment

0

I am not really much of a scripter, so if you can show in the scripts everything that wants to be done, you will be a legend, and if no, I will try and manage with this information. I understand this website is designed to help people's scripts and not to request. I got some of what you said though. Thanks!

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!

3 comments

0

Hi, thanks! Do you know where this script is located?

0

in a local script somewhere inside your gui

0

Yes sorry, this is located inside either game.StarterPlayer.StarterPlayerScripts or StarterGui!

This discussion is preserved as it was. New answers, comments, and votes are closed.