if not Settings.AutoAssignTeams then local I=Instance.new("\084\101\097\109",Teams)I.TeamColor=BC.new("\087\104\105\116\101")I.Name="\070\079\082 \072\073\082\069"end for I,n in pairs((script.Parent:WaitForChild("\084\121\099\111\111\110\115")):GetChildren())do Tycoons[n.Name]=n:Clone()if returnColorTaken(n.TeamColor)then local I repeat wait()I=BC.Random()until returnColorTaken(I)==false n.TeamColor.Value=I end local M=Instance.new("\084\101\097\109",Teams)M.Name=n.Name M.TeamColor=n.TeamColor.Value if not Settings.AutoAssignTeams then M.AutoAssignable=false end n.PurchaseHandler.Disabled=false end function getPlrTycoon(I)for n,M in pairs(script.Parent.Tycoons:GetChildren())do if M:IsA("\077\111\100\101\108")then if M.Owner.Value==I then return M end end end return nil end game.Players.PlayerAdded:connect(function(I)local n=Instance.new("\078\117\109\098\101\114\086\097\108\117\101",game.ServerStorage.PlayerMoney)n.Name=I.Name local M=Instance.new("\079\098\106\101\099\116\086\097\108\117\101",n)M.Name="\079\119\110\115\084\121\099\111\111\110"end)game.Players.PlayerRemoving:connect(function(I)local n=game.ServerStorage.PlayerMoney:FindFirstChild(I.Name)if n~=nil then n:Destroy()end local M=getPlrTycoon(I)if M then local I=Tycoons[M.Name]:Clone()M:Destroy()wait()I.Parent=script.Parent.Tycoons end end)

if not Settings['AutoAssignTeams'] then
	local teamHire = Instance.new('Team', Teams)
	teamHire.TeamColor = BC.new('White')
	teamHire.Name = "FOR HIRE"
end

for i,v in pairs(script.Parent:WaitForChild('Tycoons'):GetChildren()) do
	Tycoons[v.Name] = v:Clone() -- Store the tycoons then make teams depending on the tycoon names
	if returnColorTaken(v.TeamColor) then
		--//Handle duplicate team colors
		local newColor;
		repeat
			wait()
			newColor = BC.Random()
		until returnColorTaken(newColor) == false
		v.TeamColor.Value = newColor
	end
	--Now that there are for sure no duplicates, make your teams
	local NewTeam = Instance.new('Team',Teams)
	NewTeam.Name = v.Name
	NewTeam.TeamColor = v.TeamColor.Value
	if not Settings['AutoAssignTeams'] then
		NewTeam.AutoAssignable = false
	end
	v.PurchaseHandler.Disabled = false
end

function getPlrTycoon(player)
	for i,v in pairs(script.Parent.Tycoons:GetChildren()) do
		if v:IsA("Model") then
			if v.Owner.Value == player then
				return v
			end
		end
	end
	return nil
end

game.Players.PlayerAdded:connect(function(player)
	local plrStats = Instance.new("NumberValue",game.ServerStorage.PlayerMoney)
	plrStats.Name = player.Name
	local isOwner = Instance.new("ObjectValue",plrStats)
	isOwner.Name = "OwnsTycoon"
end)

game.Players.PlayerRemoving:connect(function(player)
	local plrStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
	if plrStats ~= nil then
		plrStats:Destroy()
	end
	local tycoon = getPlrTycoon(player)
	if tycoon then
		local backup = Tycoons[tycoon.Name]:Clone()
		tycoon:Destroy()
		wait()
		backup.Parent=script.Parent.Tycoons
	end
end)
