PrimaryPart is not a valid member of folder

Im not sure what to put, what do i put?

local newArmor = replicatedstorage.Armors:Clone()
local camera = Instance.new("Camera")
		camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
		camera.Parent = newTemplate.ViewportFrame

Whole script

local replicatedstorage = game:GetService("ReplicatedStorage")
	local function addToFrame(armor)
		local template = script.Parent.MainGui.Inventory.Templates.Template
		
		local newTemplate = template:Clone()
		newTemplate.Parent =  script.Parent.MainGui.Inventory.Duplicates
		newTemplate.Visible = true
		
		local newArmor = replicatedstorage.Armors:Clone()
		
		local camera = Instance.new("Camera")
		camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
		camera.Parent = newTemplate.ViewportFrame
		
		newTemplate.ViewportFrame.CurrentCamera = camera
end

replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
	addToFrame(armor)
end)
1 Like

Armors is most likely a folder. PrimaryPart is a property of a model

1 Like

How do I get the random model chosen in the folder? Because I already made a rarity script and it chooses randomly but how would I get that chosen model/armor

1 Like
local children = folder:GetChildren()
local randomChildren = children[math.random(1, #children]

something like this should work. It gets the length of the folder, and then selects a random index between 1 and the length

1 Like

I already have that In a another script I’m just trying to figure out how to get that chosen model from a different script

1 Like

Heres the script for the module chooserandomarmor

local armormodule = {}

armormodule.armors = {
	["Legendary"] = {
		game.ReplicatedStorage.Armors.LegendaryArmor
	};

	["Epic"] = {
		game.ReplicatedStorage.Armors.EpicArmor
	}

}

armormodule.rarities = {
	["Legendary"] = .0001; -- 0.001% chance

	["Epic"] = 10; --10% chance 

}

local sum = 0
for i, v in pairs(armormodule.rarities) do
	sum += v
end


armormodule.chooseRandom = function()

	local randomNumber = math.random()*sum

	local counter = 0

	for rarity, weight in pairs(armormodule.rarities) do
		counter = counter + weight
		if randomNumber <= counter then

			local rarityTable = armormodule.armors[rarity]
			local chosenArmor = rarityTable[math.random(1,#rarityTable)]
			return chosenArmor

		end
	end

end

return armormodule
1 Like

You should probably use it in your script then

local armormodule = require(...)
local newArmor = armormodule.chooseRandom():Clone()
1 Like

it’s just stuck in an infinite yield, and doesn ntohing

local replicatedstorage = game:GetService("ReplicatedStorage")
local armormodule = require(game.ServerScriptService:WaitForChild("ArmorHandler"))
	local function addToFrame(armor)
		local template = script.Parent.MainGui.Inventory.Templates.Template
		
		local newTemplate = template:Clone()
		newTemplate.Parent =  script.Parent.MainGui.Inventory.Duplicates
		newTemplate.Visible = true
		
		local newArmor = armormodule.chooseRandom():Clone()
		
		local camera = Instance.new("Camera")
		camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
		camera.Parent = newTemplate.ViewportFrame
		
		newTemplate.ViewportFrame.CurrentCamera = camera
end

replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
	addToFrame(armor)
end)

When you made the camera instance, don’t you have to state what you want the parent to be? Also, please clarify is armors a folder? Also in line 12 of that whole script, don’t you need to add another bracket somewhere, the fact that you specifically sent that part of the script implies there may be an error there, or the output, says something about line 12, so I’m guessing the problem is there

Edit: ah yes, after reading the title, I think newArmor is a folder in that case, the title says it all and so did @Jxl_s, folders don’t have primary parts, only models do