What do you want to achieve? I want to use the for i = 1,100 format to create information UI’s that have different Values but are inside the same class(more detailed description below, I’m also pretty new at scripting).
What is the issue? for the past few days I’ve been trying to clone this template(screenshot below) using the for i = 1,100 format and also change the “CarName” Text Label, and the “viewCar” ViewPortFrame to display the owned vehicle. I’ve been successful at cloning the template to the correct amount of owned vehicles, displaying the car. I haven’t tried the selling or spawn yet but that should be pretty self explanatory once I get these 2 figured out.
I can do it individually no problem but for 1 it’ll take up a lot more time and 2 it will be very messy and to confusing if i decide to come back to this script at a later time.
if you don’t understand what I am trying to do yet because tbh I’m not great at explaining so I’ll put it here. I wish to use the for i = 1,100(for my case the amount of cars owned) format and clone the template posted above. that I have done. but my 2 issues are changing the “CarName” text to the owned cars text and a viewport of the car(in some context I have that done but once I own 2 cars or more it changes the name to another owned car and stacks all the viewport frames on top of each other in every cloned template. image posted below, also along with how i want it to look.) each car has a folder called “Assets” and has the following (CarName which is a string value, Horsepower which is a int value, Price which is a int value, and ZeroToSixty which is a string value) all of those assets are being used inside the shop but I can still use the CarName string to display the name. what I’m about to say next is sketch but it works for now but when the player purchases a car it gets added to a folder called “OwnedCars” and gets placed under a string value with the name and value of the cars name(so for instance the Ford GT would be placed under a new string called “Ford GT” and the value would be called “Ford GT”).
I don’t think I’m missing anything. The main point is set across and the extra information is just so you can understand it a little better. I really apologize for the long post for probably something so simple but it’s really been bugging me and I’d more than greatly appreciate if this got resolved.
What solutions have you tried so far? I accidentally listed what I’ve tried above but I’ve also tried to look up my issue in different contexts, I’ve tried countless things on my own like placement of the script(s) up to just trying random things that somewhat make sense in my head, I’ve tried reading up on the LUA helping page + reading up on posts that inquire the format I want.
-- I can send a code block of what I have but it's very messy because for 1 I'm new and for 2 I'm just messing with it right now trying to see what might work
I am not asking for full scripts I am just asking for guidance or a reference so I can also learn from this. also I apologize again for the long post but I really have no idea on how to explain this so everyone can understand. if you have any questions feel free to ask I will answer all of them as best as possible.
Hi, I’ve gotta eat dinner but I’ll send you my script when I’m done, I’ll also try what you said because my template is currently in a folder called “Templates” under replicated storage.
sorry for the long wait but here. if you want the variables too i can send them. but i didn’t think they were necessary
InventoryFrame:GetPropertyChangedSignal("Visible"):Connect(function()
if InventoryFrame.Visible == false then
--when the inventory frame is closed it deletes the current templates
for i, v in pairs(ContainerFrame:GetDescendants()) do
if v.ClassName == "Frame" then
v.Visible = false
v:Destroy()
end
end
elseif InventoryFrame.Visible == true then
--for each car they own it will clone the template
for i = 1, AmntOfOwnedCars.Value do
--if the player doesn't own any cars then it won't display any templates
if AmntOfOwnedCars.Value == 0 then return end
local clonedOwnedCarInfoTemplate = OwnedCarInfoTemplate:Clone()
clonedOwnedCarInfoTemplate.Parent = ContainerFrame
clonedOwnedCarInfoTemplate.Visible = true
clonedOwnedCarInfoTemplate.Name = "OwnedCarInfoTemplate"..i
local OwnedCarsDescendants = OwnedCars:GetDescendants()
for i, v in pairs(OwnedCarsDescendants) do
if v:IsA("Folder") and v.Name == "Assets" then
local Car = v.Parent
local Assets = v
clonedOwnedCarInfoTemplate.CarName.Text = Assets.CarName.Value
local clonedCar = Car:Clone()
clonedCar.Parent = clonedOwnedCarInfoTemplate.viewCar
local Camera = Instance.new("Camera", clonedOwnedCarInfoTemplate.viewCar)
Camera.Name = "viewCarCamera"
Camera.CFrame = CFrame.new(-188.413, 5.2, -411) * CFrame.Angles(math.rad(-21.629),math.rad(41.95),math.rad(14))
clonedOwnedCarInfoTemplate.viewCar.CurrentCamera = Camera
end
end
end
end
end)
Why do you need AmntOfOwnedCars.Value when you can just loop over OwnedCars:GetDescendants()? I also don’t think it’s necessary to delete and re-add templates every time. I know you’re trying to save GUI space/memory but it might actually be worse because you have to keep deleting and re-adding them.
Code:
InventoryFrame:GetPropertyChangedSignal("Visible"):Connect(function()
if InventoryFrame.Visible then
--for each car they own it will clone the template
for i, descendant in OwnedCars:GetDescendants() do
if descendant:IsA("Folder") and descendant.Name == "Assets" then
local Car = descendant.Parent
local Assets = descendant
print("Car detected: " Assets.CarName.Value)
local clonedOwnedCarInfoTemplate = OwnedCarInfoTemplate:Clone()
clonedOwnedCarInfoTemplate.Visible = true
clonedOwnedCarInfoTemplate.Parent = ContainerFrame
clonedOwnedCarInfoTemplate.CarName.Text = Assets.CarName.Value
local clonedCar = Car:Clone()
clonedCar.Parent = clonedOwnedCarInfoTemplate.viewCar
local Camera = Instance.new("Camera")
Camera.Name = "viewCarCamera"
Camera.CFrame = CFrame.new(-188.413, 5.2, -411) * CFrame.Angles(math.rad(-21.629), math.rad(41.95), math.rad(14))
Camera.Parent = clonedOwnedCarInfoTemplate.viewCar
clonedOwnedCarInfoTemplate.viewCar.CurrentCamera = Camera
end
end
else
--when the inventory frame is closed it deletes the current templates
for i, v in ContainerFrame:GetChildren() do
if v:IsA("Frame") then
v:Destroy()
end
end
end
end)
yea I can see why it can make it worse now that someone said it lol, thank you. and that code worked perfectly. it printed this: Car detected: Shelby GT 500 , where you said:
print("Car detected: " Assets.CarName.Value)
there was an underlined error so I just fixed it to
print("Car detected: "..Assets.CarName.Value)
thank you again this was taking so long to figure out I was so tempted to do it individually. seriously, thank you.