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)
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
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
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