– Services
local ReplicatedStorage = game:GetService(“ReplicatedStorage”) – The service for Replicated Storage
local Players = game:GetService(“Players”) – The service for players
local Teams = game:GetService(“Teams”) – The service for teams
local ServerStorage = game:GetService(“ServerStorage”) – The service for Serverstorage
local dss = game:GetService(“DataStoreService”) – The service for DataStore
– DataStores
local teamStore = dss:GetDataStore(“TeamStore”)
local teamPlayers = {}
local function RandomTeam(plr)
local teams = Teams:GetTeams()
local randomTeam = teams[math.random(1, #teams)]
– local Team = ServerStorage.Plrs:FindFirstChild(plr.UserId):WaitForChild(“pLRdATA”).Team.Value
local function RemovePlayer(plr)
– local Team = ServerStorage.Plrs:FindFirstChild(plr.UserId):WaitForChild(“pLRdATA”).Team.Value
– local Team = Teams:FindFirstChild(plr.Team)
local Team = teamPlayers[plr]
print(Team)
teamStore:SetAsync(plr.UserId, Team)
print(“saved”)
print(teamStore:GetAsync(plr.UserId))
end
local function PlayerJoining(plr)
local result
local success, err = pcall(function()
result = teamStore:GetAsync(plr.UserId)
end)
if not success then
warn(err)
return
end
if result then
plr.Team = Teams:FindFirstChild(result)
else
RandomTeam(plr)
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local dss = game:GetService("DataStoreService")
local teamStore = dss:GetDataStore("TeamStore")
local teamPlayers = {}
local function RandomTeam(plr)
local teams = Teams:GetTeams()
local randomTeam = teams[math.random(1, #teams)]
plr.Team = randomTeam
teamPlayers[plr] = randomTeam
end
local function RemovePlayer(plr)
--local Team = ServerStorage.Plrs:FindFirstChild(plr.UserId):WaitForChild(“pLRdATA”).Team.Value
-- local Team = Teams:FindFirstChild(plr.Team)
local Team = teamPlayers[plr]
teamStore:SetAsync(plr.UserId, Team.Name)
end
local function PlayerJoining(plr)
local result
local success, err = pcall(function()
result = teamStore:GetAsync(plr.UserId)
end)
if not success then
warn(err)
return
end
if result then
plr.Team = Teams:FindFirstChild(result)
else
RandomTeam(plr)
end
end
game.Players.PlayerAdded:Connect(PlayerJoining)
game.Players.PlayerRemoving:Connect(RemovePlayer)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local dss = game:GetService("DataStoreService")
local teamStore = dss:GetDataStore("TeamStore")
local teamPlayers = {}
local function RandomTeam(plr)
local teams = Teams:GetChildren()
local randomTeam = teams[math.random(1, #teams)]
plr.Team = randomTeam
teamPlayers[plr] = plr.Team
end
local function RemovePlayer(plr)
--local Team = ServerStorage.Plrs:FindFirstChild(plr.UserId):WaitForChild(“pLRdATA”).Team.Value
-- local Team = Teams:FindFirstChild(plr.Team)
local Team = teamPlayers[plr]
if Team then
teamStore:SetAsync(plr.UserId, Team.Name)
end
end
local function PlayerJoining(plr)
local result
local success, err = pcall(function()
result = teamStore:GetAsync(plr.UserId)
end)
if not success then
warn(err)
return
end
if result then
plr.Team = Teams:FindFirstChild(result)
else
RandomTeam(plr)
end
end
game.Players.PlayerAdded:Connect(PlayerJoining)
game.Players.PlayerRemoving:Connect(RemovePlayer)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local dss = game:GetService("DataStoreService")
local teamStore = dss:GetDataStore("TeamStore")
local teamPlayers = {}
local prefix = "GekkeTeam"
local function RandomTeam(plr)
local teams = Teams:GetChildren()
local randomTeam = teams[math.random(1, #teams)]
plr.Team = randomTeam
teamPlayers[plr] = {
["teamName"] = plr.Team.Name;
["team"] = plr.Team
}
end
local function RemovePlayer(plr)
local Team = teamPlayers[plr].teamName
if Team then
print(Team)
teamStore:SetAsync(plr.UserId..prefix, Team)
end
end
local function PlayerJoining(plr)
local result
local success, err = pcall(function()
result = teamStore:GetAsync(plr.UserId..prefix)
end)
if not success then
warn(err)
return
end
print(result)
if result then
plr.Team = Teams:FindFirstChild(result)
teamPlayers[plr] = {
["teamName"] = result;
["team"] = plr.Team
}
else
RandomTeam(plr)
end
end
game.Players.PlayerAdded:Connect(PlayerJoining)
game.Players.PlayerRemoving:Connect(RemovePlayer)
quick update, i think this is personally better, but you choose which one.
it didnt work for me because i had the auto asign property set to true, instead of false. Thats a mistake on my behalve. What matters is that the 2 scripts should work