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

Why is my radar not working properly?

I'm trying to make a radar that shows the positions of all the players and some other humanoid models that I have in a table. This script correctly shows trackers for all the characters that I want, but doesn't position them all properly - only one or two are correct and the others are all placed at (0,0). Does anyone know why this is happening? FilteringEnabled is true. I previously tried waiting for the character's Torso, but it wouldn't find the torso, even though it existed (I'm not sure why this is happening either).

function updateTracker(v)
	local newt = tracker:Clone()
	newt.Visible = true
	newt.Parent = frame
	newt.Name = v.Name
	if v:FindFirstChild("Humanoid") then
		v.Humanoid.Changed:connect(function()
			if not v:FindFirstChild("Humanoid") or v.Humanoid.Health < 0 then newt:Destroy() end
		end)
	end
	if v:FindFirstChild("Smashable") then
		newt.BackgroundColor3 = Color3.new(0,180/255,0)
	else
		newt.BackgroundColor3 = Color3.new(0,50/255,1)
	end
	if game.Players.LocalPlayer.Name == v.Name then
		frame[v.Name].Size = UDim2.new(0,9,0,9)
	end
	frame[v.Name].Position = UDim2.new(0, -(v:GetModelCFrame().p.X)/4 + 50, 0, -(v:GetModelCFrame().p.X)/4 + 50)
end

Currently this is looping once every second through a table of players and a table of the other Humanoid models.

--MightyWanderer

1 comment

0

To wait for a torso, do character:WaitForChild("Torso")

1 answer

I'm guessing

frame[v.Name].Position = UDim2.new(0, -(v:GetModelCFrame().p.X)/4 + 50, 0, -(v:GetModelCFrame().p.X)/4 + 50)

should be

frame[v.Name].Position = UDim2.new(0, -(v:GetModelCFrame().p.X)/4 + 50, 0, -(v:GetModelCFrame().p.Z)/4 + 50)

(the second .X should be a .Z)


Also, shouldn't you first be checking to find an already existing tracker before cloning in a new one? It seems so, since you only delete them on death? Perhaps your trackers fade away. If not, though, you could try something like:

local newt = frame:FindFirstChild(v.Name) or tracker:clone();

2 comments

0

I forgot to mention that I :ClearAllChildren() to the frame before I run this on the models. I can't check to see if a tracker exists for each model, since many of them have the same name.

0

That makes sense, except in that case you should never be using frame[v.Name]. Just use newt

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