For loop puts all models inside of 1 model

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.

2 Likes

if you manage to save the instances ID then good luck, never worked for me

1 Like

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

1 Like

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

1 Like

have you tried creating a table storing all of the podium’s unique ID’s and then looping through that with ipairs?

1 Like
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
2 Likes

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 :smile: (why I said SOMETHING like the code above)

1 Like

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?

2 Likes

i guess but the issue is that they’re all named the same thing, which causes issues in referencing

1 Like

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:

image

image

dang bru what did i just spend the last hour doing :sob: :sob:

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)

1 Like

what you got is EXACTLY what I need for my game

1 Like

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()
2 Likes

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
image_2025-01-11_215351255
and my character is located inside the podium here
image_2025-01-11_215421491
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 104

could my issue be because I have findfirstchild set again?

1 Like

That error is saying NPC is nil. All you did by using FindFirstChild to access the “Character” child was prevent the index error from rising. The function call instead resulted in nil. You may be trying to access the “Character” child prematurely. Please send your full script(s)

hate to admit it but I really don’t understand that at all. I can send my scripts or I can send you the model link that I used for the prompt / UI service for the characters. which one would be best for you to help?

Your scripts are more relevant to the problem

here you go

local ShowUIEvent = game:GetService("ReplicatedStorage"):WaitForChild("HumanoidDescription")
local TryOutfitEvent = game:GetService("ReplicatedStorage"):WaitForChild("TryOutfit")
local Runs = game:GetService("RunService")
local CloseSound = script:WaitForChild("Close")
local WearSound = script:WaitForChild("Wear")
local WooshSound = script:WaitForChild("Woosh")
local viewportModelRotator = require(game.ReplicatedStorage.ViewportRotation)

local NPC = nil

----------------------------------[[ VIEWPORT PORTION ]]------------------------------

-- Settings
local OFFSET = CFrame.new(0,2.5,-7)

-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

-- Objects
local ViewPort = script.Parent.ImageLabel:WaitForChild("ViewportFrame")
local Camera = Instance.new("Camera")
ViewPort.CurrentCamera	= Camera

local ValidClasses = {
	["MeshPart"] = true; ["Part"] = true; ["Accoutrement"] = true;
	["Pants"] = true; ["Shirt"] = true;
	["Humanoid"] = true;
}

local RenderObjects = table.create(25)

local function RemoveObject(Object)
	local Clone = RenderObjects[Object]
	if not Clone then return nil end

	RenderObjects[Object] = nil
	if Clone.Parent:IsA("Accoutrement") then
		Clone.Parent:Destroy()
	else
		Clone:Destroy()
	end

	--print("Removed",Object)
end

local function AddObject(Object)
	if not ValidClasses[Object.ClassName] then
		return nil
	end

	-- Create clone, regardless of Archivable
	local a = Object.Archivable
	Object.Archivable = true
	local RenderClone = Object:Clone()
	Object.Archivable = a

	if Object.ClassName == "MeshPart" or Object.ClassName == "Part" then
		RenderObjects[Object] = RenderClone

	elseif Object:IsA("Accoutrement") then
		RenderObjects[Object.Handle] = RenderClone.Handle

	elseif Object.ClassName == "Humanoid" then
		--Disable all states. We only want it for clothing wrapping.
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.FallingDown,			false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Running,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,	false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Climbing,			false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,	false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.GettingUp,			false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Jumping,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Landed,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Flying,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Freefall,			false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Seated,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,	false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Dead,				false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Swimming,			false)
		RenderClone:SetStateEnabled(Enum.HumanoidStateType.Physics,				false)
		RenderClone.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	end

	--print("Added",Object)

	return RenderClone
end

----------------------------------[[ EVENT PORTION ]]------------------------------


ShowUIEvent.OnClientEvent:Connect(function(NPCEvent)
	
	
	NPC = NPCEvent
	WooshSound:Play()
	script.Parent.Visible = true
	
	----------------------------------[[ VIEWPORT PORTION ]]------------------------------
	
	
	RunService.Heartbeat:Connect(function()
		if (not NPC:FindFirstChild("HumanoidRootPart")) or (not ViewPort.Visible) then
			return nil
		end

		-- Update camera
		Camera.CFrame = CFrame.new(NPC.HumanoidRootPart.CFrame:ToWorldSpace(OFFSET).Position, NPC.HumanoidRootPart.Position)

		-- Update objects
		for Original, Clone in pairs(RenderObjects) do
			if Original and Original.Parent then
				Clone.CFrame = Original.CFrame
			else
				RemoveObject(Original)
			end
		end
	end)

	local function HandleChar()
		--warn("Handle char")

		table.clear(RenderObjects)
		ViewPort:ClearAllChildren()

		local Viewmodel = Instance.new("Model")
		Viewmodel.Name = "PlayerViewmodel"
		Viewmodel.Parent = ViewPort

		local CharObjects = NPC:GetDescendants()
		for i, Object in pairs(CharObjects) do
			
			local RenderClone = AddObject(Object)
			if RenderClone then
				RenderClone.Parent = Viewmodel
			end
			
		end

		NPC.DescendantAdded:Connect(function(NewObject)
			local RenderClone = AddObject(NewObject)
			if RenderClone then
				RenderClone.Parent = Viewmodel
			end
		end)
		NPC.DescendantRemoving:Connect(function(OldObject)
			RemoveObject(OldObject)
		end)
		
		
	end
	
	HandleChar()
	
	----------------------------------[[ ACCESSORIES PORTION ]]------------------------------
	

	
	for _, Child in ipairs(script.Parent.ScrollingFrame:GetChildren()) do
		if Child:IsA("Frame") then
			Child:Destroy()
		end
	end

	local Accessories = {}
	local Accessories2 = {}

	local Backs = NPC.Humanoid:WaitForChild("HumanoidDescription").BackAccessory
	local BacksTable = Backs:split(",")
	for _, Back in ipairs(BacksTable) do
		if Back ~= 0 then
			if tonumber(Back) then
				table.insert(Accessories, Back)
			end
		end
	end	

	local Face = NPC.Humanoid:WaitForChild("HumanoidDescription").FaceAccessory
	local FaceTable = Face:split(",")
	for _, FaceAC in ipairs(FaceTable) do
		if FaceAC ~= 0 then
			if tonumber(FaceAC) then
				table.insert(Accessories, FaceAC)
			end
		end
	end	

	local Fronts = NPC.Humanoid:WaitForChild("HumanoidDescription").FrontAccessory
	local FrontsTable = Fronts:split(",")
	for _, Front in ipairs(FrontsTable) do
		if Front ~= 0 then
			if tonumber(Front) then
				table.insert(Accessories, Front)
			end
		end	
	end

	local Hairs = NPC.Humanoid:WaitForChild("HumanoidDescription").HairAccessory
	local HairsTable = Hairs:split(",")
	for _, Hair in ipairs(HairsTable) do
		if Hair ~= 0 then
			if tonumber(Hair) then
				table.insert(Accessories, Hair)
			end
		end
	end

	local Hats = NPC.Humanoid:WaitForChild("HumanoidDescription").HatAccessory
	local HatsTable = Hats:split(",")
	for _, Hat in ipairs(HatsTable) do
		if Hat ~= 0 then
			if tonumber(Hat) then
				table.insert(Accessories, Hat)
			end
		end
	end

	local Necks = NPC.Humanoid:WaitForChild("HumanoidDescription").NeckAccessory
	local NecksTable = Necks:split(",")
	for _, Neck in ipairs(NecksTable) do
		if Neck ~= 0 then
			if tonumber(Neck) then
				table.insert(Accessories, Neck)
			end
		end
	end

	local Shoulders = NPC.Humanoid:WaitForChild("HumanoidDescription").ShouldersAccessory
	local ShouldersTable = Shoulders:split(",")
	for _, Shoulder in ipairs(ShouldersTable) do
		if Shoulder ~= 0 then
			if tonumber(Shoulder) then
				table.insert(Accessories, Shoulder)
			end
		end
	end

	local Waists = NPC.Humanoid:WaitForChild("HumanoidDescription").WaistAccessory
	local WaistsTable = Waists:split(",")
	for _, Waist in ipairs(WaistsTable) do
		if Waist ~=  0 then
			if tonumber(Waist) then
				table.insert(Accessories, Waist)
			end
		end
	end

	local Face = NPC.Humanoid:WaitForChild("HumanoidDescription").Face
	if tonumber(Face) then
		table.insert(Accessories, Face)
	end	

	local Shirt = NPC.Humanoid:WaitForChild("HumanoidDescription").Shirt
	if tonumber(Shirt) then
		table.insert(Accessories, Shirt)
	end	

	local Pants = NPC.Humanoid:WaitForChild("HumanoidDescription").Pants
	if tonumber(Pants) then
		table.insert(Accessories, Pants)
	end	

	local GraphicTShirt = NPC.Humanoid:WaitForChild("HumanoidDescription").GraphicTShirt
	if tonumber(GraphicTShirt) then
		table.insert(Accessories, GraphicTShirt)
	end	
	
	local AdditionalAccessories = NPC.Humanoid:WaitForChild("HumanoidDescription"):GetAttribute("ExtraAccessories")
	if AdditionalAccessories then
		local ExtraTable = AdditionalAccessories:split(",")
		for _, Extra in ipairs(ExtraTable) do
			if Extra ~=  0 then
				if tonumber(Extra) then
					table.insert(Accessories, Extra)
				end
			end
		end
	end
	
	local BuggedAccessories = NPC.Humanoid:WaitForChild("HumanoidDescription"):GetAttribute("Priceless")
	if BuggedAccessories then
		local BuggedTable = BuggedAccessories:split(",")
		for _, Bugged in ipairs(BuggedTable) do
			if Bugged ~=  0 then
				if tonumber(Bugged) then
					table.insert(Accessories2, Bugged)
				end
			end
		end
	end

	local AddedTable = {}

	for _, ID in ipairs(Accessories) do
		if ID ~= 0 then
			if tonumber(ID) then
				if not table.find(AddedTable, ID) then
					table.insert(AddedTable, ID)
					local Template = script.Template

					local NewTemplate = Template:Clone()
					NewTemplate.ProductIDVal.Value = ID
					NewTemplate.AssetIcon.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=" .. ID .. "&width=420&height=420&format=png"

					NewTemplate.Parent = script.Parent.ScrollingFrame
				end
			end
		end
	end
	
	print("Finished first table")
	
	for _, ID in ipairs(Accessories2) do
		print("Going through accessories2")
		if ID ~= 0 then
			print("ID ~= 0")
			if tonumber(ID) then
				print("Got ID")
				if not table.find(AddedTable, ID) then
					print("Creating button")
					table.insert(AddedTable, ID)
					local Template = script.Template

					local NewTemplate = Template:Clone()
					NewTemplate.ProductIDVal.Value = ID
					NewTemplate.AssetIcon.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=" .. ID .. "&width=420&height=420&format=png"
					NewTemplate.Cost.Text = "Offsale"

					NewTemplate.Parent = script.Parent.ScrollingFrame
				end
			end
		end
	end
	
end)

----------------------------------[[ CLOSE/TRY PORTION ]]------------------------------

local CloseButton = script.Parent:WaitForChild("Close")
local TryButton = script.Parent:WaitForChild("Try")

TryButton.Activated:Connect(function()
	TryOutfitEvent:FireServer(NPC)
	WearSound:Play()
end)

CloseButton.Activated:Connect(function()
	script.Parent.Visible = false
	CloseSound:Play()
end)
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ShowUIEvent = game:GetService("ReplicatedStorage"):WaitForChild("HumanoidDescription")
local TryOutfitEvent = game:GetService("ReplicatedStorage"):WaitForChild("TryOutfit")

local OutfitsFolder = ReplicatedFirst:WaitForChild("Outfits")
local Row1Folder = OutfitsFolder:WaitForChild("Row1")
local Row2Folder = OutfitsFolder:WaitForChild("Row2")
local Row3Folder = OutfitsFolder:WaitForChild("Row3")
local Row4Folder = OutfitsFolder:WaitForChild("Row4")
local Row5Folder = OutfitsFolder:WaitForChild("Row5")
local Row6Folder = OutfitsFolder:WaitForChild("Row6")
local CreatorPicksFolder = OutfitsFolder:WaitForChild("CreatorPicks")

local MainFolder = game:GetService("Workspace"):WaitForChild("Main")
local Outfits = MainFolder:WaitForChild("Outfits")
local Row1 = Outfits:WaitForChild("Row1")
local Row2 = Outfits:WaitForChild("Row2")
local Row3 = Outfits:WaitForChild("Row3")
local Row4 = Outfits:WaitForChild("Row4")
local Row5 = Outfits:WaitForChild("Row5")
local Row6 = Outfits:WaitForChild("Row6")
local CreatorPicks = Outfits:WaitForChild("CreatorPicks")

wait(1)
local CharactersArray = ReplicatedFirst:WaitForChild("Outfits"):WaitForChild("Row1Characters"):GetChildren()
local PodiumsArray = Row1:GetChildren()

for index, character in CharactersArray do
	
	local podium = assert(PodiumsArray[index], "Insufficent number of podiums.")
	character.Parent = podium
end
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ShowUIEvent = game:GetService("ReplicatedStorage"):WaitForChild("HumanoidDescription")
local TryOutfitEvent = game:GetService("ReplicatedStorage"):WaitForChild("TryOutfit")

local OutfitsFolder = ReplicatedFirst:WaitForChild("Outfits")
local Row1Folder = OutfitsFolder:WaitForChild("Row1")
local Row2Folder = OutfitsFolder:WaitForChild("Row2")
local Row3Folder = OutfitsFolder:WaitForChild("Row3")
local Row4Folder = OutfitsFolder:WaitForChild("Row4")
local Row5Folder = OutfitsFolder:WaitForChild("Row5")
local Row6Folder = OutfitsFolder:WaitForChild("Row6")
local CreatorPicksFolder = OutfitsFolder:WaitForChild("CreatorPicks")

local MainFolder = game:GetService("Workspace"):WaitForChild("Main")
local Outfits = MainFolder:WaitForChild("Outfits")
local Row1 = Outfits:WaitForChild("Row1")
local Row2 = Outfits:WaitForChild("Row2")
local Row3 = Outfits:WaitForChild("Row3")
local Row4 = Outfits:WaitForChild("Row4")
local Row5 = Outfits:WaitForChild("Row5")
local Row6 = Outfits:WaitForChild("Row6")
local CreatorPicks = Outfits:WaitForChild("CreatorPicks")

--Row1:FindFirstChild("DistancePart"):Destroy()
Row2:FindFirstChild("DistancePart"):Destroy()
Row3:FindFirstChild("DistancePart"):Destroy()
Row4:FindFirstChild("DistancePart"):Destroy()
Row5:FindFirstChild("DistancePart"):Destroy()
Row6:FindFirstChild("DistancePart"):Destroy()
CreatorPicks:FindFirstChild("DistancePart"):Destroy()

wait(1)
for _, v in ipairs(Row1Folder:GetChildren()) do
	if v:IsA("Model") and v.Name == "Podium" then
		
		
		v.Parent = Row1
	end
end


task.wait(3)
for _, v in ipairs(Row1:GetChildren()) do
	if v:IsA("Model") then

		local newProximityPrompt = Instance.new("ProximityPrompt")
		newProximityPrompt.ActionText = ""
		newProximityPrompt.HoldDuration = 0.5
		newProximityPrompt.MaxActivationDistance = 5
		newProximityPrompt.Parent = v:WaitForChild("ProximityPart")

		local takeScript = v:WaitForChild("ProximityPart"):WaitForChild("takeScript")
		takeScript.Parent = v:WaitForChild("ProximityPart"):WaitForChild("ProximityPrompt")

		print("made prompt")

		newProximityPrompt.Triggered:Connect(function(Player)

			local NPC = takeScript.Parent.Parent.Parent:FindFirstChild("Character")
			local Character = Player.Character
			ShowUIEvent:FireClient(Player, NPC)
		end)

		TryOutfitEvent.OnServerEvent:Connect(function(Player, NPC)

			local Character = Player.Character
			if NPC == takeScript.Parent.Parent.Parent.Character then
				local Desc = takeScript.Parent.Parent.Parent.Character.Humanoid:GetAppliedDescription()
				if Desc and Character then
					Character:WaitForChild("Humanoid"):ApplyDescription(Desc)
				end
			end
			
			newProximityPrompt.Enabled = false
			task.wait(0.1)
			newProximityPrompt.Enabled = true
		end)
	end
end

I know some of it’s formatted horrible so don’t attack me on that please :sob: but that’s all the scripts that relate to the character. everything else is just little effects for marketplace service when they purchase something which has no correlation to the character so I decided to leave those out