Help with Crate Roll system

I have the following code to roll a crate visually, the only part of it that is broken is the tween part, where it rolls but lands up on the wrong cell, I know its because some properties are being assigned wrong but i dont know how to do it correctly. The “Moving” Frame has a UIGridLayout inside of it with the following properties: CellPadding: {0, 5},{0, 5}, CellSize = {0.041, 0},{1, 0}. If that helps anyhow

Here is the code:

local event = game.ReplicatedStorage.Spin

local RaritiesModule = require(game.ReplicatedStorage:WaitForChild("Rarities"))

local spinDB = false

local RaritiesTable = RaritiesModule.Rarities

local TS = game:GetService("TweenService")

local RewardPosition = UDim2.new(0,0,0,0)

function spin(ammount, player, award)
	
	local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Quart)
	local tween = TS:Create(player.PlayerGui.RollTest.Frame.Moving, tweenInfo, {Position = RewardPosition}) 
	tween:Play()
	tween.Completed:Wait() 


	task.wait(2)
	player.PlayerGui.RollTest.Award.Visible = true
	player.PlayerGui.RollTest.Award.TextLabel.Text = "You won "..award
	task.wait(4)

	for i, v in pairs(player.PlayerGui.RollTest.Frame.Moving:GetChildren()) do
		if v:IsA("TextLabel") then
			v:Destroy()
		end
	end
	
	
	player.PlayerGui.RollTest.Frame.Moving.Position = UDim2.new(0,0,0,0)
	player.PlayerGui.RollTest.Award.Visible = false
	player.PlayerGui.RollTest.Frame.Visible = false
	RewardPosition = UDim2.new(0,0,0,0)
	
	spinDB = false
end


function addItems(player)
	local ammount = math.random(35,50)

	for i = 1,ammount do
		local rarity = math.random(1,100)

		local chosenRarity

		for i, v in pairs(RaritiesTable) do
			if rarity >= v[1] and rarity <= v[2] then
				chosenRarity = i
				local TextClone = game.ReplicatedStorage.MovingClone:Clone()
				TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
				TextClone.Text = i
				RewardPosition -= UDim2.new(0.035,0,0,0)
				break
			end
		end
	end

	player.PlayerGui.RollTest.Frame.Visible = true

	local chosenAward
	local rarity = math.random(1,100)

	for i, v in pairs(RaritiesTable) do
		if rarity >= v[1] and rarity <= v[2] then
			chosenAward = i
			local TextClone = game.ReplicatedStorage.MovingClone:Clone()
			TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
			TextClone.Text = i
			break
		end
	end


	for i = 1,5 do
		local rarity = math.random(1,100)

		local chosenRarity

		for i, v in pairs(RaritiesTable) do
			if rarity >= v[1] and rarity <= v[2] then
				chosenRarity = i
				local TextClone = game.ReplicatedStorage.MovingClone:Clone()
				TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
				TextClone.Text = i
				break
			end
		end
	end

	print("Chosen Award", chosenAward)

	spin(ammount, player, chosenAward)

end

event.OnServerEvent:Connect(function(player)
	if spinDB then return end

	spinDB = true
	addItems(player)

end)

Im extremely confused, -0.25 is the X scale needed to move one of the TextClones offscreen but when for each one I move the UI to the left it just does not work at all and I don’t undestand

local event = game.ReplicatedStorage.Spin

local RaritiesModule = require(game.ReplicatedStorage:WaitForChild("Rarities"))

local spinDB = false

local RaritiesTable = RaritiesModule.Rarities

local TS = game:GetService("TweenService")

local RewardPosition = UDim2.new(0,0,0,0)

function spin(ammount, player, award)
	
	print(ammount)
	
	player.PlayerGui.RollTest.Frame.Moving.Position = RewardPosition
	--local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Quart)
	--local tween = TS:Create(player.PlayerGui.RollTest.Frame.Moving, tweenInfo, {Position = RewardPosition}) 
	--tween:Play()
	--tween.Completed:Wait() 


	task.wait(10000)
	player.PlayerGui.RollTest.Award.Visible = true
	player.PlayerGui.RollTest.Award.TextLabel.Text = "You won "..award
	task.wait(4)

	for i, v in pairs(player.PlayerGui.RollTest.Frame.Moving:GetChildren()) do
		if v:IsA("TextLabel") then
			v:Destroy()
		end
	end
	
	
	player.PlayerGui.RollTest.Frame.Moving.Position = UDim2.new(0,0,0,0)
	player.PlayerGui.RollTest.Award.Visible = false
	player.PlayerGui.RollTest.Frame.Visible = false
	RewardPosition = UDim2.new(0,0,0,0)
	
	spinDB = false
end


function addItems(player)
	local ammount = math.random(35,50)

	for i = 1,ammount do
		local rarity = math.random(1,100)

		local chosenRarity
		local TextClone
		
		for i, v in pairs(RaritiesTable) do
			if rarity >= v[1] and rarity <= v[2] then
				chosenRarity = i
				TextClone = game.ReplicatedStorage.MovingClone:Clone()
				TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
				TextClone.Text = i
				break
			end
		end
		RewardPosition -= UDim2.new(0.25, 0,0,0)
	end

	player.PlayerGui.RollTest.Frame.Visible = true

	local chosenAward
	local rarity = math.random(1,100)

	for i, v in pairs(RaritiesTable) do
		if rarity >= v[1] and rarity <= v[2] then
			chosenAward = i
			local TextClone = game.ReplicatedStorage.MovingClone:Clone()
			TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
			TextClone.Text = i
			break
		end
	end


	for i = 1,5 do
		local rarity = math.random(1,100)

		local chosenRarity

		for i, v in pairs(RaritiesTable) do
			if rarity >= v[1] and rarity <= v[2] then
				chosenRarity = i
				local TextClone = game.ReplicatedStorage.MovingClone:Clone()
				TextClone.Parent = player.PlayerGui.RollTest.Frame.Moving
				TextClone.Text = i
				break
			end
		end
	end

	print("Chosen Award", chosenAward)

	spin(ammount, player, chosenAward)

end

event.OnServerEvent:Connect(function(player)
	if spinDB then return end

	spinDB = true
	addItems(player)

end)

Here is what the UI looks like

Fixed the Issue was that the moving frame wasnt large enough and the text labels that indicate reward where being moved down to the next row, I just made it a lot bigger and it works now

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.