Hey! So I want to put all my models inside of other models. more in depth explanation here:
this is what it does
what I need is for 1 of each character model to go inside 1 of each podium. there’s 28 podiums and 28 characters. whenever I execute my code is does what is shown above. I’m pretty sure I have to use a for loop but I just can’t seem to get the for loop to actually execute it for each. it just randomly puts all the characters into one podium. I’ve tried doing for i = 1, #folder do
(folder being the folder that holds these podiums) but that doesn’t work. I’ve been working on work arounds for almost 2 days now on my issue and this is the closest I can get to resolving it. any help is appreciated. THANKS!
you could just number the podiums like “Podium1”, “Podium2” and so on, thr you put in the loop:
for i, podium in pairs(folder:GetChildren())
character.Parent = "Podium"..tostring(i)
end
something like that
Well what I’d do (not that I’ve tested it) is get a list of every podium. Something like
local PodiumTable = {}
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Podium" then
table.insert(PodiumTable,v)
end
end
Then do the same for every character (same code as above just different table and different name).
Then something like
for i = 1, #CharacterTable do
CharacterTable[i].Parent = PodiumTable[i]
end
to put one character into one podium. (Reminder I didn’t test it)
no this wont work, you would only get the podiums numbered in the table and not in the explorer
just number all of them you can use this command for a faster way
for i, v in pairs(folder:GetChildren())
if v.Name == "Podium" then
v.Name == "Podium"..i
I disagree (knowing that I did absolutely no testing and have not scripted in months).
I think just grabbing every podium and placing them into a table is fine, they’d all be indexed in an order. Table[1] is a different podium than Table[10]. You wouldn’t have to account for updating the names of all podiums every time you make more or delete some, then ensuring you don’t have duplicate names.
I don’t think numbering each podium is necessary.
if you manage to save the instances ID then good luck, never worked for me
sorry for late reply I couldn’t get on but I just tried your solution and it didn’t work. it gave me the same output as I was getting before. the podiums string worked so all the podiums were numbered but all the characters just went into the same podium
I can’t do this because if I changed the name of the character models it would mess up my whole prompt script and then everything else following. it searches for a model named character
have you tried creating a table storing all of the podium’s unique ID’s and then looping through that with ipairs?
local characters = -- Array of characters
local podiums = -- Array of podiums
for index, character in characters do
local podium = assert(podiums[index], "Insufficient number of podiums.")
character.Parent = podium
end
you should try putting the podiums into a folder, then giving each podium an IntValue called “PodiumId”, that way they’re individually accessible, and do →
something like:
local podiums = {} -- gets all the podiums
for i, v in pairs(game.Workspace.PodiumsFolder:GetChildren()) do
if v.Name == "Podium" then
table.insert(podiums, v)
end
end
local podiumIds = {} -- gets all of the podiums intValues
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Podium" then
local podiumId = v:WaitForChild("PodiumId")
podiumId = podiumId.Value
table.insert(podiums, podiumId)
end
end
local characters = {}
game.Players.CharacterAdded:Connect(function(player)) -- adds character to characters table on load
local clonedCharacter = character:Clone() -- CLONES the character, so we dont parent the real character to the podium
table.insert(characters, clonedCharacter)
end
for i, v in ipairs(chacracters) do -- loops through all characters
local chosenPodiumId = table.find(PodiumIds, i) -- gets a podiumId
for i, v in pairs(game.Workspace.PodiumsFolder) do -- loops through all podiums
local podiumID = v:WaitForChild("PodiumId")
podiumID = podiumID.Value -- gets the podium's ID
if v == podiumID then -- checks if the chosen ID equals the podium's ID
character.Parent = v -- sets the character clone's parent to the podium
character.CFrame = v.CFrame -- sets CFrame to podium CFrame bc why not
end
end
end
i spent like 40 minutes on this lol, also dont expect it to work fully, as i’m still learning, but i did my best (why I said SOMETHING like the code above)
I feel like OP’s problem has been vastly overcomplicated. Why do all this? Is the goal not simply to pair one model from one array to another?
i guess but the issue is that they’re all named the same thing, which causes issues in referencing
There is no need to reference any of the podiums or characters by name. Here are the results from the code in my earlier reply:
dang bru what did i just spend the last hour doing
yes you’re correct all I’m trying to achieve is put the each character into each podium. I’m gonna try your solution right now but can you explain what array would be? I’m fairly new to scripting and I’m not 100% sure what you mean by “array of characters” and “array of podiums”. is it just the location?
edit: is the array just getting the children of the folder?(that’s what makes the most sense to me considering you didn’t put :GetChildren() inside your for loop)
what you got is EXACTLY what I need for my game
An array is a particular arrangement of a table. It is characterized by a table solely comprised of values whose indices are in ascending numerical order, starting from 1. That occurs naturally with the following syntax:
local array = {"A", "B", "C"}
If your characters and podiums are stored under another instance, similar to how mine were under a Folder
, then you can produce an array that contains them by calling Instance:GetChildren:
local characters = workspace.Characters:GetChildren()
local podiums = workspace.Podiums:GetChildren()
thank you for the clarification on it and the solution. I’m getting an error when I try to trigger my prompts and here’s a screenshot
this is line 60
and my character is located inside the podium here
this is an error I keep getting
edit: what you told me to do fixed the characters all going into one podium, but this error occurs
edit again: was able to work around it just by using FindFirstChild() but now I’m getting an error inside of my handler(for the ui that gets prompted when the prompt is triggered) saying
attempt to index nil with FindFirstChild
and this is the line that’s prompting the error. line 104could my issue be because I have findfirstchild set again?