Fail table checking

i tried make a script that make a frame appear next to every character near the player’s cursor, but this is looping nonstop, even tho i have a table.find to check, maybe its not working?

the video

the code:

if isRecon then

		local params = RaycastParams.new()
		params.FilterDescendantsInstances = {char}
		params.IgnoreWater = true
		params.FilterType = Enum.RaycastFilterType.Exclude
		local hit:Vector3 = customFunctions.GetCenterOfScreenHit(500, params)

        table.clear(reconnaissanceTargets)

		for i,hum:Humanoid in pairs(Humans) do
			local targetchar:Model = hum.Parent
			local hrp:Part = targetchar.HumanoidRootPart or targetchar.PrimaryPart

			local dist = (hrp.Position - hit).Magnitude
			
			local plrchar = players:GetPlayerFromCharacter(targetchar)
			if dist <= reconRadius then
				if not table.find(reconnaissanceTargets, targetchar) then
					if not plrchar or plrchar.Team ~= plr.Team then
						table.insert(reconnaissanceTargets, targetchar)
					end
				end
			end
		end

		print(reconnaissanceTargets)

	else
		if #reconnaissanceTargets ~= 0 then
			table.clear(reconnaissanceTargets)
		end
	end
	
	for i,character:Model in pairs(reconnaissanceTargets) do
		local UI = nil
		if not table.find(reconnaissanceUi, character) then UI = Instance.new("Frame")
		UI.Size = UDim2.new(0, 50, 0, 50)
		UI.AnchorPoint = Vector2.new(0.5, 0.5)
		UI.Parent = reconnaissanceScreen
		reconnaissanceUi[character] = {["UI"] = UI}
		else UI = reconnaissanceUi[character].UI end
		
		if not UI then return end
		
		local hrp:Part = character.HumanoidRootPart or character.PrimaryPart
		local uipos = workspace.CurrentCamera:WorldToScreenPoint(hrp.Position)
		
		local screenPoint = Vector2.new(uipos.X, uipos.Y)
		UI.Position = UDim2.new(0, screenPoint.X, 0, screenPoint.Y)
	end
	
	for i,v in pairs(reconnaissanceUi) do
		local UI = v.UI
		if not v then UI:Destroy() end
	end

Taking a quick glance a this, I believe the issue is that you should be checking if reconnaissanceUi[character] == true rather than using table.find.

This is because table.find tries to find a value within the table that is equal to the argument passed, but you need to be searching if an there is an index equal to the argument passed, which by checking reconnaissanceUi[character] == true does.

sorry for the delay! I noticed this while I was out of home too, I can’t believe I didn’t notice that! small mistake but gave me a little headache

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