Hi, im trying to make a case and inventory system with viewport frames to show the items. however, in the case animation, some of the items it runs through dont show up, the first slot of the inventory is always blank and sometimes it combines items.
case cycle script
script.Parent.TextButton.MouseButton1Click:Connect(function()
if player.leaderstats.Cash.Value >= script.Parent.price.Value then
if debounce == false then
game.ReplicatedStorage.Cases.BuyCase:FireServer()
script.Parent.jp.Visible = true
script.Parent.jp.Frame.Rarity.TextColor3 = Color3.new(255, 255, 255)
script.Parent.jp.Frame.title.Text = "None"
debounce = true
for count = 1,20 do
game.SoundService.Click:Play()
local items5 = game.ReplicatedStorage.Items.Free
local items1 = getItem(ItemTable)
local Rarity = items1.Rarity
local n1 = items1.Name
script.Parent.jp.Frame.ViewportFrame:ClearAllChildren()
local image = items5:FindFirstChild(n1):Clone()
image.Parent = script.Parent.jp.Frame:WaitForChild("ViewportFrame")
task.wait(0.2)
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(image.Handle.Position + (image.Handle.CFrame.lookVector * 2),image.Handle.Position)
camera.Parent = script.Parent.jp.Frame.ViewportFrame
script.Parent.jp.Frame.ViewportFrame.CurrentCamera = camera
script.Parent.jp.Frame.title.Text = items1.Name
script.Parent.jp.Frame.Rarity.Text = items1.Rarity
for i, v in ipairs(colour) do
if v.Rarity == Rarity then
script.Parent.jp.Frame.Rarity.TextColor3 = v.Color
end
end
end
Inventory
local UserInputService = game:GetService("UserInputService")
local template = script:WaitForChild("Template")
local List = script.Parent
game.ReplicatedStorage.Inventory.sellItem.OnClientEvent:Connect(function(unboxed)
print(unboxed)
local button = template:Clone()
button.Visible = true
button.Parent = List
local item = game.ReplicatedStorage.Items:WaitForChild("total")
local image = item:FindFirstChild(unboxed):Clone()
image.Parent = script.Template:WaitForChild("ViewportFrame")
task.wait(0.2)
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(image.Handle.Position + (image.Handle.CFrame.lookVector * 2),image.Handle.Position)
camera.Parent = script.Template:WaitForChild("ViewportFrame")
script.Template:WaitForChild("ViewportFrame").CurrentCamera = camera
end)