How can I reference a specific model in Workspace?

Hi all, I have a GUI in PlayerGUI (or, it will be when it’s in use), and I need it to always reference a specific model of which there might be multiple copies, any ideas how I could do this?

Additional context:
Developing an AG-Chassis (essentially modified a-chassis) plugin, and need to reference a specific car model from PlayerGUI to change some TextLabels

When each car is created, store a reference of it, so you dont need to look for it on workspace, and just grab it directly from a table of references.

But I think I need more context about your system. The plugin creates the cars? the cars are already there?

The cars are cloned from ServerStorage into workspace via a separate GUI, the plugin only changes a TextLabel based upon inputs from the plugin GUI.

How would I go about creating a table?

If you intend for this to be a plugin, you can have the user select the model they wish to use it on, and use the Selection service. Hope that helps.

I just realised, this came across as a Studio plugin, I mean it’s a plugin for AG-Chassis, it will provide the user with a custom UI, which has several buttons, and based on what the click will change a TextLabel. However I need to reference the vehicle which that UI is linked to. The vehicle provides the UI when they are in the drivers seat.

In other words, I just need a Script in PlayerGUI to reference a specific model (assuming there are multiple copies of it)

CC: @Dev_Peashie

A-Chassis has an Owner value does it not? If so, you can reference each one, check the Owner value, and then store the proper reference based on who the GUI is for.

That’s… a good idea. I’ll try it now and get back to you.

Okay, AG does have the owner value, but I haven’t got a clue how I would do the rest of what you said (scripting is not a strength of mine, evidently)

I haven’t touched A-Chassis in forever, so I’m not exactly sure as to how it goes about parenting and spawning, but assuming they’re all named “Vehicle” in workspace (they may also be named the Player’s name, iirc) we can do it like so:

(Also, I will assume the ‘Owner’ value is an Object value, not a String value, and that ‘GUI’ is the GUI in PlayerGUI)

local PlayerVehicle = nil -- This will be the proper vehicle.
local Player = GUI:FindFirstAncestorWhichIsA("Player")

-- Loop through workspace (This assumes there's no Vehicle folder)
for Index, Object in pairs(workspace:GetChildren()) do
  if Object.Name == "Vehicle" or Object.Name:Find("Vehicle") and Object:IsA("Model") then
    local OwnerValue = Object.Owner.Value -- Or it may be Object.Values.Owner.Value
    if OwnerValue.Value == Player then
      PlayerVehicle = Object
    end
  end
end

Wait Wait, scratch that. If you’re using A-Chassis 6.81 by Novena (or I assume most others will also be this way)
You can just do this.

(This assumes AChassisUI is the primary ‘A-Chassis Interface’ gui)

local PlayerCar = AChassisUI.Car.Value

Would this be a script inside the Frame, or something else?

It could be, or it could be the main script overseeing the plugin, I suppose.

GUI isn’t defined, so roblox is having a seizure, is it meant to be PlayerGUI?

No, rather, the GUI variable is meant to be the default A Chassis GUI.

Ah, right.

(man i love the restriction on length!)