Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my radar not working properly?

Asked by 10 years ago

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

0
To wait for a torso, do character:WaitForChild("Torso") 2eggnog 981 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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();
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. MightyWanderer 30 — 10y
0
That makes sense, except in that case you should never be using `frame[v.Name]`. Just use `newt` BlueTaslem 18071 — 10y
Ad

Answer this question