Hello, so I am trying to make a car game and I can’t seem to figure out how to change each GUI’s text labels(CarName, Horsepower, 0-60) to the cars information. all of the cars information is inside a folder inside the cars model.
I have tried doing a ‘for i, v in pairs(children) do’ inside the ‘for i = 1, count do’ loop but that didn’t work. I tried to add another type of ‘for i, v in pairs’ but instead of “i” and “v” I used “j” and “f” inside that prior ‘for i, v in pairs’. I tried just aimlessly placing it inside the ‘for i = 1, count’ loop but that didn’t work either. I tried looking it up under different circumstances but I couldn’t find anything similar to my issue. I’m pretty new to scripting so if some of my code is sloppy I apologize but I also added little notes above each segment of my code so you might be able to understand it a little better. I attached a few screenshots under my code block here so you can also see where some things are located. this is all being done inside a local script called ‘Manager’ inside the ‘ShopGui’ so there are some more scripts inside it too but they aren’t relevant I just thought it should be said. Thank you for your time!
--when the player clicks a tab it will clear all current GUI'S inside 'activeContainer' if any were found
CoupeTab.CoupeTab.MouseButton1Click:Connect(function()
CoupeTab.CoupeTab.MouseButton1Up:Wait()
--variables to get the number of children inside 'activeContainer'
local activeChildren = ActiveContainer:GetChildren()
local activeCount = #activeChildren
--if there is more children other than the 'UIGridLayout' inside the 'activeContainer' then it deletes them
if activeCount > 1 then
for i, v in pairs(ActiveContainer:GetDescendants()) do
if v.ClassName == "Frame" then
v.Visible = false
v:Destroy()
end
end
end
--title on the top of the gui
Title.Text = "Coupe"
--variables to get the number of children inside the correct tab folder
local children = CoupeShopTab:GetChildren()
local count = #children
--for loop to clone the correct amount of info GUI's into 'activeContainer'
for i = 1, count do
local clonedCarInfoTemplate = CarInfoTemplate:Clone()
clonedCarInfoTemplate.Parent = ActiveContainer
clonedCarInfoTemplate.Visible = true
end
end)
the ‘CarInfoTemplate’ gets dragged out of replicated storage and cloned I just dragged it out so you guys can visualize the info template easier. also I apologize for the topic title I just couldn’t think of anything that is short enough that would make sense. Thanks again!
This should work, can you show me the values? Any errors? I don’t see why this wouldn’t work. The code was kind of confusing. Couldn’t you just loop through all the assets and update their corresponding textlabel? Also, make sure you are editing the client’s PlayerGui, not StarterGui.
yes in some context that works but what you gave me isn’t the solution I need, that’s what I keep doing. and by “that” I mean this: with the for loop it takes the first child(which is the cars model) and it only uses that one and changes the text labels of all the GUI’s(as shown inside the screenshot above) to that first childs values. when I posted I had shared a screenshot of the values(which is the first screenshot and the values are under ‘assets’). no I do not get any errors. and yes they are all being edited under the players GUI.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Players = game:GetService("Players");
local Player = Players.LocalPlayer;
for _, car in pairs(ReplicatedStorage.ShopTabs:GetChildren()) do
local Frame = ReplicatedStorage.Templates.CarInfoTemplate:Clone();
Frame.Parent = Player.PlayerGui.ShopGui.ShopFrame.Container.ActiveContainer;
for _, detail in pairs(car.Assets:GetChildren()) do
local parallel = Frame[detail.Name];
parallel.Text = tostring(detail.Value);
end;
end;
I tried what you sent word for word just to see and it didn’t work. I then tried to mess around with it, where I place it. nothing. no matter where I place it I get this error:
where it says "Assets is not a valid member of Folder “ReplicatedStorage.ShopTabs.Classic” the child of ‘ShopTabs’ changes every time I relaunch it, sometimes it will say Coupe, sometimes Classic and then Muscle. If you scroll back up to my post there is a screenshot of the location of the ‘Assets’ Folder. I also just took a more clear screenshot of the ‘ShopTabs’ Folder.
and just to restate, under each child of ‘ShopTabs’ there is certain number of car models correlating to the place it is put inside the shop frame. so in order of the shop frame classic has 1 car, muscle has 2 cars, and coupe has 3 cars. each one is setup the same with the assets folder and its components inside.
Well, it seems like the asset information you put is inside the models. Move it up one in the workspace so it is in the folder. Please try to debug silly issues like this that are fairly self explanatory by yourself.
Sorry, it seems like I have misunderstood your ‘Taxonomy’. I have mistaken your categories as individual cars, however, this is still quite self-explanatory as you could easily edit my for loop to accommodate. Here is the solution:
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Players = game:GetService("Players");
local Player = Players.LocalPlayer;
for _, category in pairs(ReplicatedStorage.ShopTabs:GetChildren()) do
for _, car in pairs(category:GetChildren()) do
local Frame = ReplicatedStorage.Templates.CarInfoTemplate:Clone();
Frame.Parent = Player.PlayerGui.ShopGui.ShopFrame.Container.ActiveContainer;
for _, detail in pairs(car.Assets:GetChildren()) do
local parallel = Frame[detail.Name];
parallel.Text = tostring(detail.Value);
end;
end;
end;