local function Z(Z)Z.CharacterAdded:Connect(function(e)local t=e:WaitForChild("\072\117\109\097\110\111\105\100")local U=main.pd[Z]if U then for e,t in pairs(U.CommandsActive)do local U=Z local J={Z}local f=main.commands[string.lower(e)];(main:GetModule("\099\102")):ExecuteCommand(U,J,f,{ExtraDetails={DontForceActivate=true}})end for e,t in pairs(U.Items)do(main:GetModule("\069\120\116\101\110\115\105\111\110\115")):SetupItem(Z,e,true)end end wait(1)if settingUpPlayer[Z]then repeat wait(.1)until not settingUpPlayer[Z]end end)local e=Z.UserId if main.banned[tostring(e)]then Z:Kick("\n\n\089\111\117\'\114\101 \112\101\114\109\097\110\101\110\116\108\121 \098\097\110\110\101\100 \102\114\111\109 \116\104\105\115 \103\097\109\101\046\n\n")end settingUpPlayer[Z]=true local t=(main:GetModule("\080\108\097\121\101\114\068\097\116\097")):SetupPlayerData(Z)settingUpPlayer[Z]=nil if not main.players:GetPlayerByUserId(e)then return end Z.Chatted:Connect(function(e)main.signals.PlayerChatted:Fire(Z,e);(main:GetModule("\080\097\114\115\101\114")):ParseMessage(Z,e,true)end)local U=(main:GetModule("\099\102")):GetFriends(e)if not main.pd[Z]then return end main.pd[Z].Friends=U if not main.players:GetPlayerByUserId(e)then return end for e,t in pairs(t.DefaultSettings)do local U=main.settings[e]if U~=t then main.pd[Z].DefaultSettings[e]=U;(main:GetModule("\080\108\097\121\101\114\068\097\116\097")):ChangeStat(Z,e,U)end end;(main:GetModule("\080\108\097\121\101\114\068\097\116\097")):ChangeStat(Z,"\083\101\116\117\112\068\097\116\097",true)if e==main.ownerId or(main:GetModule("\099\102")):FindValue(main.owner,e)then(main:GetModule("\099\102")):RankPlayerSimple(Z,8,true)if main.oldLoader then main.signals.ShowWarning:FireClient(Z,"\079\108\100\076\111\097\100\101\114")end end local J=main.serverAdmins[Z.Name]if J then(main:GetModule("\099\102")):RankPlayerSimple(Z,J)end local f=main.permissions.specificUsers[Z.Name]if f then(main:GetModule("\099\102")):RankPlayerSimple(Z,f,true)end for U,J in pairs(main.permissions.gamepasses)do local f=false if(main:GetModule("\099\102")):FindValue(t.Gamepasses,U)then f=true elseif main.marketplaceService:UserOwnsGamePassAsync(e,U)then f=true;(main:GetModule("\080\108\097\121\101\114\068\097\116\097")):InsertStat(Z,"\071\097\109\101\112\097\115\115\101\115",U);(main:GetModule("\099\102")):CheckAndRankToDonor(Z,t,U)end if f then(main:GetModule("\099\102")):RankPlayerSimple(Z,J.Rank,true)end end if not main.players:GetPlayerByUserId(e)then return end for e,U in pairs(main.permissions.assets)do local J=false if(main:GetModule("\099\102")):FindValue(t.Assets,e)then J=true elseif main.marketplaceService:PlayerOwnsAsset(Z,e)then J=true;(main:GetModule("\080\108\097\121\101\114\068\097\116\097")):InsertStat(Z,"\065\115\115\101\116\115",e)end if J then(main:GetModule("\099\102")):RankPlayerSimple(Z,U.Rank,true)end end if not main.players:GetPlayerByUserId(e)then return end for e,t in pairs(main.permissions.groups)do local U=Z:GetRoleInGroup(e)if t.Roles[U]then(main:GetModule("\099\102")):RankPlayerSimple(Z,t.Roles[U].Rank,true)end end if not main.players:GetPlayerByUserId(e)then return end for e,t in pairs(U)do if t==main.ownerId then(main:GetModule("\099\102")):RankPlayerSimple(Z,main.permissions.friends,true)end end local B=game.VIPServerOwnerId if B~=0 then if e==B then(main:GetModule("\099\102")):RankPlayerSimple(Z,main.permissions.vipServerOwner,true)else(main:GetModule("\099\102")):RankPlayerSimple(Z,main.permissions.vipServerPlayer,true)end end local D=main.permissions.freeAdmin if tonumber(D)and D>0 then(main:GetModule("\099\102")):RankPlayerSimple(Z,D,true)end if t.Rank<main.ranksAllowedToJoin then Z:Kick("\084\104\101 \115\101\114\118\101\114 \104\097\115 \098\101\101\110 \108\111\099\107\101\100 \102\111\114 \114\097\110\107\115 \098\101\108\111\119 \'"..((main:GetModule("\099\102")):GetRankName(main.ranksAllowedToJoin).."\'"))for e,U in pairs(main.players:GetChildren())do main.signals.Hint:FireClient(U,{"\083\116\097\110\100\097\114\100";"\083\101\114\118\101\114 \076\111\099\107\058 "..(Z.Name..(" \097\116\116\101\109\112\116\101\100 \116\111 \106\111\105\110\033 \082\097\110\107 \061 \'"..((main:GetModule("\099\102")):GetRankName(t.Rank).."\'"))),Color3.fromRGB(255,255,255)})end end local i,N=pcall(function()return main.serverBans[(main:GetModule("\099\102")):FindUserIdInRecord(main.serverBans,e)]end)if not N then i,N=pcall(function()return main.sd.Banland.Records[(main:GetModule("\099\102")):FindUserIdInRecord(main.sd.Banland.Records,e)]end)end if i and N then(main:GetModule("\099\102")):BanPlayer(Z.UserId,N)end if t.SaveRank and(main:GetModule("\099\102")):GetRankName(t.Rank)==""then(main:GetModule("\099\102")):Unrank(Z)end wait(2)if not main.players:GetPlayerByUserId(e)then return end local h for Z,e in pairs(main.settings.ChatColors)do if t.Rank==Z then h=e break end end if h then local t=main.chatService:GetSpeaker(Z.Name)if not t then local U=10 for U=1,U,1 do wait(.5)if not main.players:GetPlayerByUserId(e)then return end t=main.chatService:GetSpeaker(Z.Name)if t then break end end end if t then t:SetExtraData("\067\104\097\116\067\111\108\111\114",h)end end wait(1)if not main.players:GetPlayerByUserId(e)then return end if t.Rank>0 and main.settings.WelcomeRankNotice~=false then local e=(main:GetModule("\099\102")):GetRankName(t.Rank);(main:GetModule("\099\102")):FormatAndFireNotice(Z,"\087\101\108\099\111\109\101\082\097\110\107",e)end if t.Donor and main.settings.WelcomeDonorNotice~=false then(main:GetModule("\099\102")):DonorNotice(Z,t)end end
-- << LOCAL FUNCTIONS >>
local function playerAdded(player)
	-- Character Added
	player.CharacterAdded:Connect(function(character)
		--Check if any commands need re-activating
		local humanoid = character:WaitForChild("Humanoid")
		local pdata = main.pd[player]
		if pdata then
			for commandName, _ in pairs(pdata.CommandsActive) do
				local speaker = player
				local args = { player }
				local command = main.commands[string.lower(commandName)]
				main:GetModule("cf")
					:ExecuteCommand(speaker, args, command, { ExtraDetails = { DontForceActivate = true } })
				--main:GetModule("Extensions"):SetupCommand(player, commandName, true)
			end
			for itemName, _ in pairs(pdata.Items) do
				main:GetModule("Extensions"):SetupItem(player, itemName, true)
			end
		end

		--Other
		wait(1)
		if settingUpPlayer[player] then
			repeat
				wait(0.1)
			until not settingUpPlayer[player]
		end
	end)

	--Check if loader banned
	local userId = player.UserId
	if main.banned[tostring(userId)] then
		player:Kick("\n\nYou're permanently banned from this game.\n\n")
	end

	-- Setup PlayerData
	settingUpPlayer[player] = true
	local pdata = main:GetModule("PlayerData"):SetupPlayerData(player)
	settingUpPlayer[player] = nil

	--Player Chatted
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	player.Chatted:Connect(function(message)
		main.signals.PlayerChatted:Fire(player, message)
		main:GetModule("Parser"):ParseMessage(player, message, true)
	end)

	--Setup Friends
	local friends = main:GetModule("cf"):GetFriends(userId)
	if not main.pd[player] then
		return
	end
	main.pd[player].Friends = friends

	-- Check if default settings have changed
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	for settingName, settingValue in pairs(pdata.DefaultSettings) do
		local defaultSettingValue = main.settings[settingName]
		--print(settingName.." : "..tostring(defaultSettingValue).." : ".. tostring(settingValue))
		if defaultSettingValue ~= settingValue then
			main.pd[player].DefaultSettings[settingName] = defaultSettingValue
			main:GetModule("PlayerData"):ChangeStat(player, settingName, defaultSettingValue)
		end
	end

	--
	main:GetModule("PlayerData"):ChangeStat(player, "SetupData", true)
	--

	-- << SETUP RANKS >>
	--Owner
	if userId == main.ownerId or main:GetModule("cf"):FindValue(main.owner, userId) then
		main:GetModule("cf"):RankPlayerSimple(player, 8, true)
		if main.oldLoader then
			main.signals.ShowWarning:FireClient(player, "OldLoader")
		end
	end

	--Check if player has admin in this server
	local serverRank = main.serverAdmins[player.Name]
	if serverRank then
		main:GetModule("cf"):RankPlayerSimple(player, serverRank)
	end

	--Specific User
	local specificUserRank = main.permissions.specificUsers[player.Name]
	if specificUserRank then
		main:GetModule("cf"):RankPlayerSimple(player, specificUserRank, true)
	end

	--Gamepasses
	for gamepassId, gamepassInfo in pairs(main.permissions.gamepasses) do
		local hasGamepass = false
		if main:GetModule("cf"):FindValue(pdata.Gamepasses, gamepassId) then
			hasGamepass = true
		elseif main.marketplaceService:UserOwnsGamePassAsync(userId, gamepassId) then
			hasGamepass = true
			main:GetModule("PlayerData"):InsertStat(player, "Gamepasses", gamepassId)
			main:GetModule("cf"):CheckAndRankToDonor(player, pdata, gamepassId)
		end
		if hasGamepass then
			main:GetModule("cf"):RankPlayerSimple(player, gamepassInfo.Rank, true)
		end
	end

	--Assets
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	for assetId, assetInfo in pairs(main.permissions.assets) do
		local hasAsset = false
		if main:GetModule("cf"):FindValue(pdata.Assets, assetId) then
			hasAsset = true
		elseif main.marketplaceService:PlayerOwnsAsset(player, assetId) then
			hasAsset = true
			main:GetModule("PlayerData"):InsertStat(player, "Assets", assetId)
		end
		if hasAsset then
			main:GetModule("cf"):RankPlayerSimple(player, assetInfo.Rank, true)
		end
	end

	--Groups
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	for groupId, groupInfo in pairs(main.permissions.groups) do
		local roleName = player:GetRoleInGroup(groupId)
		if groupInfo.Roles[roleName] then
			main:GetModule("cf"):RankPlayerSimple(player, groupInfo.Roles[roleName].Rank, true)
		end
	end

	--Friends
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	for plrName, plrId in pairs(friends) do
		if plrId == main.ownerId then
			main:GetModule("cf"):RankPlayerSimple(player, main.permissions.friends, true)
		end
	end

	--VIPServers
	local vipServerOwnerId = game.VIPServerOwnerId
	if vipServerOwnerId ~= 0 then
		if userId == vipServerOwnerId then
			main:GetModule("cf"):RankPlayerSimple(player, main.permissions.vipServerOwner, true)
		else
			main:GetModule("cf"):RankPlayerSimple(player, main.permissions.vipServerPlayer, true)
		end
	end

	--Free admin
	local freeAdminRank = main.permissions.freeAdmin
	if tonumber(freeAdminRank) and freeAdminRank > 0 then
		main:GetModule("cf"):RankPlayerSimple(player, freeAdminRank, true)
	end

	-- << CHECK FOR SERVER LOCK >>
	if pdata.Rank < main.ranksAllowedToJoin then
		player:Kick(
			"The server has been locked for ranks below '"
				.. main:GetModule("cf"):GetRankName(main.ranksAllowedToJoin)
				.. "'"
		)
		for i, plr in pairs(main.players:GetChildren()) do
			main.signals.Hint:FireClient(
				plr,
				{
					"Standard",
					"Server Lock: " .. player.Name .. " attempted to join! Rank = '" .. main:GetModule("cf")
						:GetRankName(pdata.Rank) .. "'",
					Color3.fromRGB(255, 255, 255),
				}
			)
		end
	end

	-- << CHECK IF BANNED >>
	--local success, record = false, main.serverBans[main:GetModule("cf"):FindUserIdInRecord(main.serverBans, userId)]
	local success, record = pcall(function()
		return main.serverBans[main:GetModule("cf"):FindUserIdInRecord(main.serverBans, userId)]
	end)
	if not record then
		success, record = pcall(function()
			return main.sd.Banland.Records[main:GetModule("cf"):FindUserIdInRecord(main.sd.Banland.Records, userId)]
		end)
	end
	if success and record then
		main:GetModule("cf"):BanPlayer(player.UserId, record)
	end

	-- << CHECK PERM RANK AND RANK EXISTS >>
	if pdata.SaveRank and main:GetModule("cf"):GetRankName(pdata.Rank) == "" then
		main:GetModule("cf"):Unrank(player)
	end

	-- << START COLOUR >>
	wait(2)
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	--Setup start chat colour
	local plrChatColor
	for chatRankId, chatColor3 in pairs(main.settings.ChatColors) do
		if pdata.Rank == chatRankId then
			plrChatColor = chatColor3
			break
		end
	end
	if plrChatColor then
		local speaker = main.chatService:GetSpeaker(player.Name)
		if not speaker then
			local maxRetries = 10
			for i = 1, maxRetries do
				wait(0.5)
				if not main.players:GetPlayerByUserId(userId) then
					return
				end
				speaker = main.chatService:GetSpeaker(player.Name)
				if speaker then
					break
				end
			end
		end
		if speaker then
			speaker:SetExtraData("ChatColor", plrChatColor)
		end
	end

	-- << NOTICES >>
	wait(1)
	if not main.players:GetPlayerByUserId(userId) then
		return
	end
	if pdata.Rank > 0 and main.settings.WelcomeRankNotice ~= false then
		local rankName = main:GetModule("cf"):GetRankName(pdata.Rank)
		main:GetModule("cf"):FormatAndFireNotice(player, "WelcomeRank", rankName)
	end
	if pdata.Donor and main.settings.WelcomeDonorNotice ~= false then
		main:GetModule("cf"):DonorNotice(player, pdata)
	end
	--main.signals.FadeInIcon:FireClient(player)
end
