These actually aren’t terribly hard to make, so you’ll be using the Rotation property on the UI Instance, and resetting the rotation back to 0 each time you call your spin function.
Step 1: Create a wheel rewards module
-- This is an array of rewards
local rewardsModule = {
rewardOne, -- Index 1
rewardTwo, -- Index 2
rewardThree, -- Index 3
rewardFour, -- Index 4
rewardFive, -- Index 5
rewardSix, -- Index 6
rewardSeven, -- Index 7
rewardEight -- Index 8
}
return rewardsModule
Step 2: Finding the angles:
A full circle is 360°
You have 8 prizes on the wheel so you need to divide the circle by 8
360/8 = 45° per reward
local REWARD_DEGREE = 45
Step 3: Get angle of reward number
local randomRewardIndex = rewardsModule[math.random(1, #rewardsModule)]
local targetRotationAngle = (randomRewardIndex - 1) * REWARD_DEGREE -- the angle on the wheel the prize will be at
The reason behind subtracting randomRewardIndex by 1 is because our start rotation on the wheel is 0 for position 1. Therefore you need to subtract the randomRewardIndex by 1 to get the correct angle, as shown on the wheel picture example above.
Step 4: Tween the rotation of UI Instance to our targetRotationAngle
local fullSpins = 4 -- how many times during the tween we want the wheel to spin before landing on our prize
local endRotation = (360 * fullSpins) * targetRotationAngle
local tween = TweenService:Create(instance, tweenInfo, {
Rotation = endRotation
})
instance.Rotation = 0 -- reset this or else over time the angle won't be accurate.
tween:Play() -- play the rotation animation!