Crate spin system gap bug

Hello all,
I’ve used this community tutorial to create a crate spin system. Although i experience some weird behaviour:

Does anyone know why sometimes when it spins, one spin it goes to the right and the next spin goes left? Also, I get this weird gap after spinning.

da856b97d2d52c4c4d30e1602a387bbbd6a19b1d

--Begining spinner
spiner.Crates.Visible = true

local crateSizeX = crateTemplate.AbsoluteSize.X
local crateGapX = 10
local crateTotalGapX = crateSizeX + crateGapX
local crates = {}
local landPosition

for i = 1, #spinDetails.Items do
   local crate = crateTemplate:Clone()
   local item = spinDetails.Items[i]
   crate.Name = "Crate" .. i
   crate.Position = crate.Position + UDim2.new(0, crateTotalGapX*(i-1), 0, 0)
   crate.About.ItemName.Text = item.Name
   crate.About.ItemRarity.Text = item.Rarity
   crate.About.BackgroundColor3 = spinDetails.Rarities[item.Rarity].Color
   crate.ImageLabel.Image = item.Image
   crate.Parent = spiner.Crates.Holder

   table.insert(crates, crate)

   if i == spinDetails.WinningItemId then
      landPosition = UDim2.new(0, line.AbsolutePosition.X - ((crate.AbsoluteSize.X / 2 + crate.AbsolutePosition.X) + math.random(-crate.AbsoluteSize.X / 2, crate.AbsoluteSize.X / 2)), 0, 0)
   end
end

local tweenTime = 7 --Alternativly use math.random(7, 8)
local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Quart)
local tween = TweenService:Create(spiner.Crates.Holder, tweenInfo, {Position = landPosition})
tween:Play()
tween.Completed:Connect(function()
wait(1)
spiner.Visible = false
for _, crate in ipairs(crates) do
   crate:Destroy()
end

if errorMessage == "Duplicate!" and duplicate then
   spiner.Crates.Visible = false
   spiner.Processing.Text = duplicate
   spiner.Processing.Visible = true
   spiner.Visible = true

   task.wait(2.5)

   spiner.Processing.Visible = false
   spiner.Visible = false
else
   --Set reward image of item image
   reward.ItemName.Text = spinDetails.WinningItem.Name
   reward.ItemRarity.Text = spinDetails.WinningItem.Rarity
   reward.ItemRarity.TextColor3 = spinDetails.Rarities[spinDetails.WinningItem.Rarity].Color
   reward.ImageLabel.Image = spinDetails.WinningItem.Image
   reward.Visible = true
   reward.CollectButton.MouseButton1Click:Connect(function()
   reward.Visible = false
   end)

   ItemAdded:Fire(spinDetails.WinningItem.Name)
end

buyDebounce = true
end)

image


If you have any questions please leave them below. Thanks for the help!

I think it’s because you forgot to start at the first item. How are they indexed in your script?

I’ve fixed already The issue. I just had to reset The holder position at every spin start. Do you know How could i convert

crate.Position = crate.Position + UDim2.new(0, crateTotalGapX*(i-1), 0, 0)
…
landPosition = UDim2.new(0, line.AbsolutePosition.X - ((crate.AbsoluteSize.X / 2 + crate.AbsolutePosition.X) + math.random(-crate.AbsoluteSize.X / 2, crate.AbsoluteSize.X / 2)), 0, 0)

To scale instead of offset?