Spinning case system problem!

So I made this script from a post I read. There are two problems 1 one is that the animation does not go as I want to the animation moves to the right, but everything in the frame should move to the left. Second if the animtion goes to the right, the templates don’t clone. There are no errors and everything prints like normal.

local tweenService = game:GetService("TweenService")
local sendAnimation = game.ReplicatedStorage.RemoteEvents.SendAnimation
local characterModule = require(game.ReplicatedStorage.CharacterModule)
local template = script.Template
local player = game.Players.LocalPlayer
local itemContainer = script.Parent.ItemContainer
local spinTime = 5

sendAnimation.OnClientEvent:Connect(function(character, chance)
	local numberOfItems = math.random(50,100)
	local chosenPosition = numberOfItems - math.random(5, 10)
	
	for i = 1, numberOfItems do
		if i ~= chosenPosition then
			local tempCharacter, tempChance = characterModule.chooseRandomCharacter(player.Values.Luck.Value)
			local newItemFrame = template:Clone()
			newItemFrame.Title.Text = tempCharacter
			newItemFrame.Chance.Text = tempChance.."%"

			newItemFrame.Parent = itemContainer
		else
			local newItemFrame = template:Clone()
			newItemFrame.Title.Text = character
			newItemFrame.Chance.Text = chance.."%"

			newItemFrame.Parent = itemContainer
		end
	end
	
	print("Lol")
	
	local cellSize = template.Size.X.Scale
	local padding = itemContainer.UIListLayout.Padding.Scale
	local nextOffset = -cellSize - padding
	local finalPosition = (0.5 - cellSize / 2) + (chosenPosition - 1) * nextOffset
	
	local spinTweenInfo = TweenInfo.new(spinTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	
	local MainInstance = itemContainer
	local X = {Scale = itemContainer.Position.X.Scale, Offset = itemContainer.Position.X.Offset}
	local Y = {Scale = itemContainer.Position.Y.Scale, Offset = itemContainer.Position.Y.Offset}
	
	local tween = tweenService:Create(MainInstance, spinTweenInfo, {Position = UDim2.new(finalPosition, X.Offset, Y.Scale, Y.Offset)}) 
	tween:Play()
	
	for _, item in pairs(itemContainer:GetChildren()) do
		if item and not item:IsA("UIListLayout") and not item:IsA("UIPadding") then
			item:Destroy()
		end
	end
end)

I got the script from this post and youtube video, the person found out what the problem was, but never told. Could someone help me?

2 Likes