How to pick a random player's string value and assign a value to it?

This module controls a lot of functions related to a round system, and I’m looking to make a function that sets a random players’ string value to something and I only know how to select a random intvalue. Any help is appreciated.

local module = {}

local Players = game:GetService("Players")

function module.TeleportPlayer(PlayerName, TeleportLocation)
	local Player = Players:FindFirstChild(PlayerName)
	if Player then
		local Character = Player.Character or Player.CharacterAdded:Wait()
		Character:FindFirstChild("HumanoidRootPart").CFrame = TeleportLocation.CFrame
	end
end

function module.TeleportPlayers(TeleportLocation)
	for Index, Player in ipairs(Players:GetChildren()) do
		module.TeleportPlayer(Player.Name, TeleportLocation)
	end
end

Players.PlayerAdded:Connect(function(Player)
	local Status = Instance.new("StringValue")
	Status.Parent = Player
	Status.Name = Player.Name
end)

return module

Here’s some pseudocode:

function module.SelectRandomPlayer()
local playerSelection = players:GetPlayers() --//Returns a table of all the player instances.
local chosenPlayer = math.random(1, #playerSelection) --//Generate a random index for the table above, with the range being 1 (the starting table index) to the length of the table/number of players in the game.

local player = playerSelection[chosenPlayer] --//Index the player that was chosen in the players table.

--//Modify their StringValue
player[player.Name].Value = "someNewValue"
end
3 Likes

Alright I’ll test this function.