Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to assign StringValues names of each players?

Asked by
R0jym 47
2 years ago
Edited 2 years ago

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)

0
if u absolutely must do it this way, tables are ur best friend :) ZeroToH3ro 82 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
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.

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 R0jym 47 — 2y
0
ah ok, good luck on ur game ZeroToH3ro 82 — 2y
Ad

Answer this question