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

How To Get A Random Players name and UserID?

I'm making the dialog for a camping game and for some parts a random player needs to talk, please help! Here is the code

--All scripts here are by Sabrna563
-- All Dialog Values

local DialogValues = game.ReplicatedStorage.DialogValues
local DiologText = DialogValues.Text.Value
local Name = DialogValues.PlayerName.Value
local UserID = DialogValues.PlayerUserID.Value
-- Game Values

local Players = game.Players
--		Funcions
--Typing Effect
local function TypeEffect(Text)
	print("Printing Dialog Text")
	for i = 1,#Text,1 do
		DiologText = string.sub(Text,1,i)
		wait(0.05)
	end
	print("Printed Text")
	print(DiologText)
end

-- Random Player text
local function RandomPlayerText(Text)
	-- Name --The Player Name
	-- UserID  --The User id
	print(text)
end

1 answer

✓ Accepted answer

Here are the variables:

local Players = game.Players:GetPlayers() -- players
local nplrs = #Players -- number of players
local Randomplayer = Players[math.random(1, nplrs)]  -- the random player

local RandomPlayerName = Randomplayer.Name -- the random player name
local RandomUserID =  Randomplayer.UserId -- the random player userid

More information: https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayers and https://developer.roblox.com/en-us/api-reference/lua-docs/math

1 comment

0

Thanks!

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