Touched Blacklist Script Help

Currently handling this script with OnServerEvent, basically prints anything with a humanoid in it that its also a model, however itll keep printing constantly, im trying to make a “blacklist” so the same player doesnt get printed and rather skips over it but im unsure of how to do that.

			local zoneTouch = zone.Touched:Connect(function(touched)
				local touchedModel = touched:FindFirstAncestorOfClass('Model')
				
				
				if touchedModel ~= nil then
					if character ~= touchedModel then
						for _, object in touchedModel:GetChildren() do
							if object:IsA('Humanoid') then
								remoteScan:FireClient(player, touchedModel)
							end
						end
					end
				end

			end) 

Entire Script:

--//Locals
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mechanics = ReplicatedStorage:WaitForChild('Mechanics')
local RemoteEvents = ReplicatedStorage:WaitForChild('RemoteEvents')
local TweenService = game:GetService("TweenService")

--//Paths
local remoteScan = RemoteEvents:WaitForChild('remoteScan')
--//

--//Client To Server
local function onScanRequest(player, timer, debounce)
	task.spawn(function()
		if not debounce then
			--// Paths
			local scanner = Mechanics:WaitForChild('ScanZone')
			local zone = scanner:Clone()
			local light = zone:WaitForChild("PointLight")
			local weld = Instance.new('WeldConstraint')
			local character = player.Character
			local HRP = character:FindFirstChild('HumanoidRootPart')
			--//

			--// Values
			local zoneSizeStart = Vector3.new(0,0,0)
			local zoneSize = Vector3.new(200,200,200)
			--//

			--// Default Settings
			weld.Parent = zone
			weld.Part0 = zone
			weld.Part1 = HRP
			zone.Size = zoneSizeStart
			zone.Position = HRP.Position
			zone.Parent = workspace
			light.Range = 0
			--//

			--// Reusable Tween function
			local function onTween(changes, cooldown, reverse, object)

				local tweenInfo = TweenInfo.new(
					cooldown,									-- Time taken for a full animation
					Enum.EasingStyle.Linear,			-- Animation Style
					Enum.EasingDirection.InOut,			-- Animation Type
					0,									-- Number of repeats (-1 is infinite)
					reverse,								-- Reverse?
					0									-- Delay between animations
				)

				local tween = TweenService:Create(object, tweenInfo, changes)

				tween:Play()
			end
			--//

			--// LocalPlayer is now scanning

			zone.Size = zoneSizeStart
			zone.Transparency = 0
			light.Range = 0
			light.Color = Color3.fromRGB(255, 255, 255)

			local zoneChanges = {
				Size = zoneSize;
				Transparency = 1
			}
			onTween(zoneChanges, timer, false, zone)

			local lightChanges = {
				Range = 160;
				Color = Color3.fromRGB(0, 0, 0)
			}
			onTween(lightChanges, timer*1.5, false, light)
			
			
			local zoneTouch = zone.Touched:Connect(function(touched)
				local touchedModel = touched:FindFirstAncestorOfClass('Model')
				
				
				if touchedModel ~= nil then
					if character ~= touchedModel then
						for _, object in touchedModel:GetChildren() do
							if object:IsA('Humanoid') then
								remoteScan:FireClient(player, touchedModel)
							end
						end
					end
				end

			end) 
						
			task.wait(timer)

			zone:Destroy()
			zoneTouch:Disconnect()
			zoneTouch = nil
			zone = nil
			

		end
		--//
	end)
end

--//

--//Function Callers
remoteScan.OnServerEvent:Connect(onScanRequest)

--//

Im confused slightly,

When you say ‘I’m trying to make a “blacklist” so the same player doesn’t get printed and rather skips over it but I’m unsure of how to do that.’;

Are you saying it will do (or iterate) the same Humanoid multiple times and continue to FireClient(player, touchedModel)?

by blacklist he means if the touched part is on blacklisted list.

Blacklist means, having a list and anything from that list is not allowed. So you can use tables as they can work like a blacklist pretty well.

yeah, so, this script its already ignoring the localplayer, its supposed to detect other players however when i tried to implement a blacklist so the print doesnt fire a thousand times for the same thing i simply just didnt know how to do it right, then again I was running on 0 sleep.

I was able to fix and finish the script thanks to a friend who helped me

--//Locals
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mechanics = ReplicatedStorage:WaitForChild('Mechanics')
local RemoteEvents = ReplicatedStorage:WaitForChild('RemoteEvents')
local TweenService = game:GetService("TweenService")

--//Paths
local remoteScan = RemoteEvents:WaitForChild('remoteScan')
--//

--//Client To Server
local function onScanRequest(player, timer, debounce)
	task.spawn(function()
		if not debounce then
			--// Paths
			local scanner = Mechanics:WaitForChild('ScanZone')
			local zone = scanner:Clone()
			local sound = zone:WaitForChild('Whistle')
			local character = player.Character
			local HRP = character:FindFirstChild('HumanoidRootPart')
			--//

			--// Values
			local zoneSizeStart = Vector3.new(0,0,0)
			local zoneSize = Vector3.new(200,200,200)
			--//

			--// Default Settings
			zone.Size = zoneSizeStart
			zone.Position = HRP.Position
			zone.Parent = workspace
			sound.Playing = true
			sound.PlaybackSpeed = math.random(6, 9) / 10
			--//

			--// Reusable Tween function
			local function onTween(changes, cooldown, reverse, object)

				local tweenInfo = TweenInfo.new(
					cooldown,									-- Time taken for a full animation
					Enum.EasingStyle.Linear,			-- Animation Style
					Enum.EasingDirection.InOut,			-- Animation Type
					0,									-- Number of repeats (-1 is infinite)
					reverse,								-- Reverse?
					0									-- Delay between animations
				)

				local tween = TweenService:Create(object, tweenInfo, changes)

				tween:Play()
			end
			--//

			--// LocalPlayer is now scanning

			zone.Size = zoneSizeStart
			zone.Transparency = 0

			local zoneChanges = {
				Size = zoneSize;
				Transparency = 1
			}
			onTween(zoneChanges, timer, false, zone)
			
			--// Player Finder
			local playerList = {}

			local zoneTouch = zone.Touched:Connect(function(touched)
				local touchedModel = touched:FindFirstAncestorOfClass('Model')
				if touchedModel == character then return end
				if touchedModel:FindFirstChild('Humanoid').Health > 0 then
					if not table.find(playerList, touchedModel) then
						table.insert(playerList, touchedModel)
						remoteScan:FireClient(player, touchedModel)
					end
				end
			end)
			--//

			task.wait(timer)
			
			--// Unplug Everything :)
			zoneTouch:Disconnect()
			zoneTouch = nil
			zone:Destroy()
			zone = nil
			
			--//


		end
	end)
end

--//

--//Function Callers
remoteScan.OnServerEvent:Connect(onScanRequest)

--//

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