Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My script is kicking everyone, but I only want it to kick non allies and non group people. Help?

Hello people of the scripters, the script is kicking all the players, but I want it to make it so it only kicks the people that aren't in the group and arent the a lies. Please help as soon as possible!

local Players = game:GetService("Players")
local allies = {}
local groupID = 10248
local pages = game:GetService("GroupService"):GetAlliesAsync(groupID)
while true do
   for _,group in pairs(pages:GetCurrentPage()) do
      table.insert(allies, group)
   end
   if pages.IsFinished then
      break
   end
   pages:AdvanceToNextPageAsync()
end
 
function OnPlayerAdded(player)
   for _,group in pairs(allies) do
      if not player:IsInGroup(group.Id) then
         player:kick()
else
	print("player is fear and is good")
      end
   end
end
 
Players.PlayerAdded:connect(OnPlayerAdded)
for _,player in pairs(Players:GetPlayers()) do
   OnPlayerAdded(player)
end

1 answer

✓ Accepted answer

You have to iterate through the table, and then determine if they need to be kicked. I'll show you how to use a bool variable to track it.

local pages = game:GetService("GroupService"):GetAlliesAsync(groupID)
local Players = game.Players
local groupID = 10248
local allies = {}

while true do
	for _,group in pairs(pages:GetCurrentPage()) do
\		table.insert(allies, group)
	end
	if pages.IsFinished then
		break
end
   pages:AdvanceToNextPageAsync()
end

function OnPlayerAdded(player)
	local getridofthem = true; --Variable placeholder
	if plr:IsInGroup(groupID) then
		getridofthem = false; --switch var if they in group
	else
		for _,group in pairs(allies) do
			if player:IsInGroup(group.Id) then
				getridofthem = false; --switch var if they in allies
			end
		end
	end
	if getridofthem then
		player:Kick() --kick them according to var
	end
end

Players.PlayerAdded:connect(OnPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
	OnPlayerAdded(player)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.