How would I make a Frame follow a part name

I’m currently making a Guided Missile and I can’t seem to find any posts related to this. What I’m trying to make is a Vehicle Marker.

So basically if you are on a radar seat you can see Vehicle Markers like this:

Screenshot 2023-12-27 144716

I am still struggling to find a script like this. I have tried making a script that detects a part with a specific name will make a gui frame follow it but it still doesn’t work.

2 Likes

Hey @officer_wiki,

it doesn’t seem intuitive to have an ImageLabel “follow” a part. Instead, instancing a BillboardGui into the desired part on command is probably what you should opt for.

local targetPart = workspace.Target -- Reference your part here
local billboardGui = Instance.new("BillboardGui") -- Customize the BillboardGui below, don't forget to add the ImageLabel


local function acquireTarget()

 billboardGui.Parent = targetPart

end

local function leaveTarget()

 billboardGui.Parent = game:GetService("ReplicatedStorage") -- You can store it anywhere you'd like

end

-- Fire acquireTarget() if the player is seated and leaveTarget() if unseated

Hope this helps!

2 Likes

Wait but is it not possible for it to be a Frame? Since the BillboardGui always gets bigger or not smaller and I want to make it same size

1 Like

Just change the pixel size of the BillboardGui, it won’t scale no matter how far or close you are to it

Screenshot 2023-12-27 171150

You can still use frame if you want to make your life 100 times harder

2 Likes

Well if I have to use then alright I guess…

Wait then how am I supposed to script it when there’s gonna be many parts. I don’t think it’s possible to detect that many since it’s random.

Wym by random?
Character limit. ------------

Assuming you have the parts you want to detect stored in a folder called “Targets”:

local targetParts = workspace.Targets -- Reference your folder here
local billboardGui = Instance.new("BillboardGui") -- Customize the BillboardGui below, don't forget to add the ImageLabel


local function acquireTarget()

 for _, target in ipairs(targetsParts:GetChildren()) do
  local billboardGuiCopy = billboardGui:Clone() -- copies the BillboardGui each time the function is called
  billboardGuiCopy.Parent = target
 end

end

local function leaveTarget()

 for _, target in ipairs(targetsParts:GetChildren()) do
   target.NameOfTheBillboardGui:Destroy() -- removes the copies again
  end

end

-- Fire acquireTarget() if the player is seated and leaveTarget() if unseated

Alternatively you can scan Workspace for parts with a specific name:

local targetName = "target" -- Set the name of the targets
local billboardGui = Instance.new("BillboardGui") -- Customize the BillboardGui below, don't forget to add the ImageLabel


local function acquireTarget()

 for _, content in ipairs(game:GetService("Workspace"):GetDescendants()) do
  if content:IsA("BasePart") and content.name == targetName then -- assuming the target is a part
   local billboardGuiCopy = billboardGui:Clone()
   billboardGuiCopy.Parent = content
  end
 end

end

local function leaveTarget()

 for _, content in ipairs(game:GetService("Workspace"):GetDescendants()) do
 
  if content:IsA("BasePart") and content.name == targetName then
   content.BillboardGuiName:Destroy()
  end
 end

end

-- Fire acquireTarget() if the player is seated and leaveTarget() if unseated

No the problem is like this:

image

How am I supposed to get all of the target billboards if they are all inside a model. Unless there is a script that finds a part name with descendant from workspace.

for _,inst in parent:GetDescendants() do
    if inst:IsA("BillboardGui") then
        --...
    end
end

(I’ve been doing it this way. Someone please tell me if there’s a more efficient method)

I still don’t know how to get the workspace descendant, It just doesn’t work.