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
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)
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.
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)