REMOTES.Chat.OnServerEvent:connect(function(S,w,J)local Z if J=="\071\108\111\098\097\108"then Z=Players:GetPlayers()elseif J=="\083\113\117\097\100"then local w=GetSquad(S)if w then Z={}for S,w in pairs(w.Players:GetChildren())do table.insert(Z,Players[w.Name])end end end if not cooldowns[S]then cooldowns[S]=0 end cooldowns[S]=cooldowns[S]+1 if cooldowns[S]<=MAX_PER_SECOND then if Z then if string.gsub(w,"\037\115","")~=""then local u=TextService:FilterStringAsync(w,S.UserId)for w,Z in pairs(Z)do spawn(function()pcall(function()if S.Parent==Players and(Z.Parent==Players and Chat:CanUsersChatAsync(S.UserId,Z.UserId))then local w=u:GetChatForUserAsync(Z.UserId)REMOTES.Chat:FireClient(Z,S.Name,w,J)end end)end)end end end else REMOTES.Chat:FireClient(S,"\083\069\082\086\069\082","\087\111\097\104 \116\104\101\114\101\044 \121\111\117\'\114\101 \115\101\110\100\105\110\103 \109\101\115\115\097\103\101\115 \116\111\111 \102\097\115\116\033","\083\101\114\118\101\114")end end)Players.PlayerRemoving:connect(function(S)if cooldowns[S]then cooldowns[S]=nil end end)
-- events

REMOTES.Chat.OnServerEvent:connect(function(player, message, scope)
	local players

	if scope == "Global" then
		players = Players:GetPlayers()
	elseif scope == "Squad" then
		local squad = GetSquad(player)
		if squad then
			players = {}

			for _, p in pairs(squad.Players:GetChildren()) do
				table.insert(players, Players[p.Name])
			end
		end
	end

	if not cooldowns[player] then
		cooldowns[player] = 0
	end

	cooldowns[player] = cooldowns[player] + 1

	if cooldowns[player] <= MAX_PER_SECOND then
		if players then
			if string.gsub(message, "%s", "") ~= "" then
				local result = TextService:FilterStringAsync(message, player.UserId)
				for _, p in pairs(players) do
					spawn(function()
						pcall(function()
							if
								player.Parent == Players
								and p.Parent == Players
								and Chat:CanUsersChatAsync(player.UserId, p.UserId)
							then
								local filtered = result:GetChatForUserAsync(p.UserId)
								REMOTES.Chat:FireClient(p, player.Name, filtered, scope)
							end
						end)
					end)
				end
			end
		end
	else
		REMOTES.Chat:FireClient(player, "SERVER", "Woah there, you're sending messages too fast!", "Server")
	end
end)

Players.PlayerRemoving:connect(function(player)
	if cooldowns[player] then
		cooldowns[player] = nil
	end
end)
