Problem with radar script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make an radar that detects stuff inside a folder in workspace , example =
    a radar will look for stuff in the artifact folder in the workspace, if something inside that folder gets near its range, it will warn the player with stuff on the tool such as a text.
  2. What is the issue? Include screenshots / videos if possible!
    so basically, the radar only detects one thing on the folder, if i get near it, it will warn me , but if i get near other thing inside the folder, nothing will happen.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried fixing on my own but ended up either breaking the script or making zero difference, i dont know why it happens, so im asking help here since most of my scripting bugs get solved here.
local radar = script.Parent
local config = script.Parent.Config
local gui = script.Parent.GUI

while true do
	wait(0.5)
	function FindTarget(radar, range)
		local bestTarget = nil

		local bestWaypoint = nil
		local bestDistance = nil
		local bestHealth = nil

		for i,mob in ipairs(workspace.Artifacts:GetChildren()) do
			local distanceToMob = (mob.RadarPart.Position - radar.Handle.Position).Magnitude

			if distanceToMob <= range then
				range = distanceToMob
				bestTarget = mob
			end

			return bestTarget
		end
	end
	local target = FindTarget(radar,config.Range.Value)
	if target then
		radar.Handle.Beep:Play()
		radar.Button.Color = Color3.new(0.564706, 1, 0.564706)
		radar.Button.PointLight.Color = Color3.new(0.564706, 1, 0.564706)
		gui.radargui.Status.Text = math.round((target.RadarPart.Position - radar.Handle.Position).Magnitude)
		gui.radargui.Status.TextColor3 = Color3.new(0.564706, 1, 0.564706)
	end
	if not target then
		radar.Button.Color = Color3.new(0.576471, 0.564706, 0.564706)
		radar.Button.PointLight.Color = Color3.new(0.576471, 0.564706, 0.564706)
		gui.radargui.Status.Text = ""
		gui.radargui.Status.TextColor3 = Color3.new(0.576471, 0.564706, 0.564706)
	end
end

the script.

Your return bestTarget is within’ the pairs loop.
Place it outside at the bottom of the for pairs loop.

Read more into it, you want a table.

local availableTargets = {}

inside of the if distanceToMob <= range then
add table.insert(availableTargets, mob)

then do return bestTarget, availableTargets

1 Like

Worked ! Never would have guessed that i needed to add tables, devforum is a savior for me !