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

How to assign StringValues names of each players?

Hello there, I have a complicated situation here where I want to make a StringValue change it's value to the player's name that joined, I don't really know on how to approach this because I can only think of all of the StringValues copying the player's name that joined instead of one player only for one StringValue only

I also want to do this for the second player that joins the server, where the second StringValue changes it's value to the second player's name that joined the server, also occuring with the other 4 StringValues, how does one do this?

local Players = game:GetService("Players")

local plr1 = game.Workspace.PlayerStrings.Player1
local plr2 = game.Workspace.PlayerStrings.Player2
local plr3 = game.Workspace.PlayerStrings.Player3
local plr4 = game.Workspace.PlayerStrings.Player4
local plr5 = game.Workspace.PlayerStrings.Player5
local plr6 = game.Workspace.PlayerStrings.Player6

local function onPlayerAdded(player)
	
	plr1.Value = player.Name
	plr2.Value = player.Name
	plr3.Value = player.Name
	plr4.Value = player.Name
	plr5.Value = player.Name
	plr6.Value = player.Name
end

for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)

1 comment

0

if u absolutely must do it this way, tables are ur best friend :)

1 answer

✓ Accepted answer
local Players = game:GetService("Players")

local PlayerStrings = game.Workspace.PlayerStrings

Players.PlayerAdded:Connect(function()
	for i, plr in pairs(Players:GetPlayers()) do
		local plrName = Instance.new("StringValue",PlayerStrings) --creating a stringValue under the folder for each player
		plrName.Name = ("Player"..i) --naming the playerString 
		plrName.Value = plr.Name --setting the playerString value to player's name
		
	end
end)

im not sure if i 100% understand ur post but this script, although a little inefficient is the best simple solution i could think of. so u want to have a empty folder under ur workspace named "PlayerStrings" and this script will create a string value for each player that joins and it will place it under the folder.

2 comments

0

Yeah that's certainl what I'm trying to create since I'm trying to make a turn based system for a dice game I have, where if a player is done rolling his dice, the dice is passed to another player

0

ah ok, good luck on ur game

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