No disrespect but your script seems to have some possible issues/bad scripting habits, and doesn’t really answer OP’s question.
So basically, when a player touches a brick, their team will change to the appropriate once and be locked to that team permanently even when they leave and rejoin.
The best way to do this is just set their team and save it as soon as they touch the part (and make sure they don’t have a team yet), then load their team back.
Here’s some untested code to help get you started:
(Sorry it’s indented weirdly I’m new to devforum)
local datastore = game:GetService("DataStoreService"):GetDataStore("Teams")
for _,v in ipairs(workspace.TeamChangers:GetChildren()) do
v.Touched:connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
if p then
if p.Team == game:GetService("Teams"):FindFirstChild("No team") then
p.Team = game:GetService("Teams"):FindFirstChild(v.Name)
local s,e = pcall(function()
datastore:SetAsync(p.UserId,v.Name)
end)
if e then warn(e) end
end
end
end)
end
game:GetService("Players").PlayerAdded:connect(function(plr)
local data = nil
local s,e = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
if e then warn(e) end
if data then
plr.Team = game:GetService("Teams"):FindFirstChild(data)
end
end)