I want it to stop rotating in the Y and Z orientation if the y and z is set to 0 and the wheel itself is also in orientation 0 then it works fine but i think because y and z sometimes is set to 180 when spinning it messes up. Or is it because of vector3?
It rotates in every direction
I have tried changing the angle
local Wheel = script.Parent -- Get a reference to the wheel object
local clickDetector = Wheel:WaitForChild("ClickDetector") -- Get a reference to the ClickDetector inside the wheel
local Replicated = game.ReplicatedStorage
local RewardsFolder = Replicated.Rewards
local Hamburger = RewardsFolder.Hamburger
local Milk = RewardsFolder.Milk
local Pizza = RewardsFolder.Pizza
local Health = RewardsFolder.Health
local rewards = {500, Pizza, 200, Hamburger, 100, Milk, 250, Health} -- Define a table of rewards
local tweenService = game:GetService("TweenService") -- Get a reference to the TweenService
local isSpinning = false -- Variable to track if the wheel is currently spinning
local Claimed = false
clickDetector.MouseClick:Connect(function(plr) -- Connect a function to the MouseClick event of the ClickDetector
local TimeManagement = plr:WaitForChild("TimeManagement")
local SpinTime = TimeManagement.FortuneReward
local TimeValue = SpinTime.Value
local Reward = game:GetService("ReplicatedStorage").Events:FindFirstChild("Fortune")
if SpinTime.Value <= 0 and Claimed == false then
if isSpinning then return end -- If the wheel is already spinning, exit the function
isSpinning = true -- Set the isSpinning variable to true to prevent multiple spins at the same time
local rewardIndex = math.random(1, #rewards) -- Choose a random index from the rewards table
local angle = rewardIndex / #rewards * 360 - (360 / #rewards / 2) -- Calculate the angle at which the wheel should stop
local offset = -math.random() * 360 / #rewards -- Add a random offset to the angle for visual variety
local spins = math.random(5, 10) * 360 -- Add a random number of extra spins to the angle
angle += offset + spins -- Calculate the final angle
local spinTime = math.random(2, 10) -- Choose a random spin time
local tweenInfo = TweenInfo.new(spinTime, Enum.EasingStyle.Quint, Enum.EasingDirection.Out) -- Create TweenInfo with the chosen spin time and easing options
local tween = tweenService:Create(Wheel, tweenInfo, {Rotation = Vector3.new(angle, -42.147, 0)}) -- Create a Tween that animates the wheel's rotation to the target angle
tween:Play() -- Start the Tween animation
tween.Completed:Wait() -- Wait for the Tween animation to complete
local rewardItem = rewards[rewardIndex] -- Get the rewarded item at the chosen index