Argument 2 missing or nil

– 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

plr.Team = randomTeam
teamPlayers[plr] = randomTeam.Name

– Team = 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]
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

end

game.Players.PlayerAdded:Connect(PlayerJoining)
game.Players.PlayerRemoving:Connect(RemovePlayer)

all in server script service obviously and i am using 5 team

yo can use " ``` " next to each other at the start and up or press
image
to make the text formated ( pls do that )

how do i do that? (I am adding this to meet the character requirement)

type or paste code here

press:

I don’t seem to have that option

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)

seems to work for me

weird i get this
image

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)

try this,

apparently i got the same team like 6 times

thank you, it works!!!

1 Like
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

ok thank you

(WHY MUST THERE BE AT LEAST 30 letters?)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.