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)