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

Setting Players' Name Inside a Value while Players are in a Specific Team?

Basically what I'm trying to do is that if players are on a team, I want them to have their own individual stringvalue. These values are in ServerStorage.

for i, v in pairs(game.Players:GetPlayers()) do
		local hometeam = game.Teams.Home
		local awayteam = game.Teams.Away
		local homeplayers1 = hometeam:GetPlayers()
		local awayplayers1 = awayteam:GetPlayers()
		if v.Team == hometeam then
			local C1 = homeplayers1[math.random(1, #homeplayers1)]
			local C2 = homeplayers1[math.random(1, #homeplayers1)]
			local C3 = homeplayers1[math.random(1, #homeplayers1)]
			local C4 = homeplayers1[math.random(1, #homeplayers1)]
			local P1 = HomePlayers:WaitForChild("Player1")
			local P2 = HomePlayers:WaitForChild("Player2")			
			local P3 = HomePlayers:WaitForChild("Player3")
			local P4 = HomePlayers:WaitForChild("Player4")
			if #homeplayers1 > 0 then
			repeat C2 = homeplayers1[math.random(1, #homeplayers1)] until C2 ~= C1 
			and C2 ~= C3 and C2 ~= C4 wait()
				if #homeplayers1 == 3 then		
				repeat C3 = homeplayers1[math.random(1, #homeplayers1)] until C3 ~= C1 
				and C3 ~= C2 and C3 ~= C4 wait()
					if #homeplayers1 == 4 then
					repeat C4 = homeplayers1[math.random(1, #homeplayers1)] until C4 ~= C1 
					and C4 ~= C3 and C4 ~= C2 wait()
					end
				end
			end
			P1.Value = C1.Name
			P2.Value = C2.Name
			P3.Value = C3.Name
			P4.Value = C4.Name
		elseif v.Team == awayteam then
			local C1 = awayplayers1[math.random(1, #awayplayers1)]
			local C2 = awayplayers1[math.random(1, #awayplayers1)]
			local C3 = awayplayers1[math.random(1, #awayplayers1)]
			local C4 = awayplayers1[math.random(1, #awayplayers1)]
			local P1 = AwayPlayers:WaitForChild("Player1")
			local P2 = AwayPlayers:WaitForChild("Player2")			
			local P3 = AwayPlayers:WaitForChild("Player3")
			local P4 = AwayPlayers:WaitForChild("Player4")
			if #awayplayers1 > 0 then
				repeat C2 = awayplayers1[math.random(1, #awayplayers1)] until C2 ~= C1 
				and C2 ~= C3 and C2 ~= C4 wait()
				if #awayplayers1 == 3 then		 
				repeat C3 = awayplayers1[math.random(1, #awayplayers1)] until C3 ~= C1 
				and C3 ~= C2 and C3 ~= C4 wait()
					if #awayplayers1 == 4 then
					repeat C4 = awayplayers1[math.random(1, #awayplayers1)] until C4 ~= C1 
					and C4 ~= C3 and C4 ~= C2 wait()
					end
				end
			end
			P1.Value = C1.Name
			P2.Value = C2.Name
			P3.Value = C3.Name
			P4.Value = C4.Name
		end
	end

Thanks,

LukeGabrieI

[Apparently this script is passed, I haven't gotten any errors, but it doesn't work.]

3 answers

✓ Accepted answer
-- // SERVICES
local Players = game:GetService('Players')
local Teams = game:GetService('Teams')

-- // CONSTANTS
local Home = Teams:WaitForChild('Home')
local Away= Teams:WaitForChild('Away')

-- // VARIABLES
local HomeTeam = {}
local AwayTeam = {}

local HomePlayerTP = workspace:WaitForChild('RedPlayerTP')
local AwayPlayerTP = workspace:WaitForChild('BluePlayerTP')

-- // FUNCTIONS
function IDENTIFY_TEAMS()
	local players = Players:GetChildren()
	for i = 1, #players do 
		if players[i].Team == Home then 
			CLEAN_TEAMS(HomeTeam) -- clean any past players in the home team

			table.insert(HomeTeam, players[i].Name) -- adds the player's name into the HomeTeam table (string value)
			print(players[i].Name .. " is in Home team!")

		elseif players[i].Team == Away then 
			CLEAN_TEAM(AwayTeam)

			table.insert(AwayTeam, players[i].Name)
			print(players[i].Name .. " is in Away team!")
		end
	end 
end

function CLEAN_TEAMS(table)
	for i = 1, #table do -- gets the children of the table
		local children = table[i]
		table.remove(table, i) -- cleans/removes the children from the table
	end
end

function TELEPORT(teamlist, tpmodel) -- call the function after you identify the teams (TELEPORT(HomeTeam, HomePlayerTP))
	for _, v in pairs(Players:GetChildren()) do 
		if v:IsA('Player') then 
			local player = v
			for i = 1, #teamlist do 
				-- lets say the teamlist = {'player1', 'player2'}
				if player.Name == teamlist[1] then -- if player name == player1 then (player1 is teamlist[1] because it's the first variable in the table)
					local torso = player.Character.Torso
					torso.CFrame  = tpmodel['1'].CFrame -- tps torso to part1
				
				elseif player.Name == teamlist[2] then -- if player name == player2 then (player2 is teamlist[2] because it's the second variable in the table)
					local torso = player.Character.Torso
					torso.CFrame  = tpmodel['2'].CFrame -- tps torso to part2
				
				elseif player.Name == teamlist[3] then 
					local torso = player.Character.Torso
					torso.CFrame  = tpmodel['3'].CFrame

				elseif player.Name == teamlist[4] then 
					local torso = player.Character.Torso
					torso.CFrame  = tpmodel['4'].CFrame
				end
			end
		end
	end
end

if game.Players.LocalPlayer.Team then game.Players.LocalPlayer.Character.Parent.Parent.ServerStorage.StringValue:Clone().Parent = game.Players.LocalPlayer end

3 comments

0

*StringValue:Clone().Parent =

0

this wouldn't work since I'm trying to accomplish something else after

0

I'm also using filtering Enabled lol, so anything locally won't be cloned

for _,p in pairs(game.Players:GetPlayers()) do
	local sv = Instance.new("StringValue")
	sv.Name = "PlayerName"
	sv.Parent = p
	sv.Value = p.Name
end

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