Why is the wheel only stopping on prize1 and nothing else?

  1. trying to make a spin to win wheel, it basically works except theres an issue with it i can’t figure out

  2. the wheel spins and such but when the wheel stops, it only lands on prize1 position and not any other prizes that are in that folder?

  3. i tried to change position value and rotation and etc i can’t figure out what to do at this point

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local RemoteEvent = ReplicatedStorage:WaitForChild("SpinWheelEvent")
local RewardsFolder = ReplicatedStorage:WaitForChild("Rewards")

-- Define the rarity of each prize (lower values are rarer)
local rarityValues = {
	Prize1 = 5,
	Prize2 = 10,
	Prize3 = 3,
	-- Add more prizes as needed
}

local isSpinning = false  -- Track whether the wheel is currently spinning

local function spinWheel(player)
	if isSpinning then
		return  -- Don't allow multiple spins while the wheel is already spinning
	end

	isSpinning = true  -- Set to true to prevent multiple spins

	-- Check if the player has enough spins to spin the wheel
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then
		warn("Leaderstats folder not found.")
		isSpinning = false  -- Reset spinning flag
		return
	end

	local spinsValue = leaderstats:FindFirstChild("Spins")
	if not spinsValue or spinsValue.Value <= 0 then
		warn("Not enough spins to spin the wheel.")
		isSpinning = false  -- Reset spinning flag
		return
	end

	-- Deduct 1 spin from the player
	spinsValue.Value = spinsValue.Value - 1

	local frame = player.PlayerGui:FindFirstChild("Spinner").Frame
	local spinwheel = frame.SpinWheel
	local WheelPrizes = spinwheel:FindFirstChild("WheelPrizes") -- this is the folder that contains ImageLabels of the prizes that are on the Wheel

	if not WheelPrizes then
		warn("WheelPrizes folder not found.")
		isSpinning = false  -- Reset spinning flag
		return
	end

	local arrow = frame.Arrow

	local prizes = WheelPrizes:GetChildren()

	-- Filter prizes based on names
	local validPrizes = {}
	for _, prize in ipairs(prizes) do
		if prize:IsA("ImageLabel") then
			table.insert(validPrizes, prize)
		end
	end

	-- Calculate the arrow's rotation
	local arrowRotation = math.deg(math.atan2(arrow.Position.Y.Offset, arrow.Position.X.Offset))
	if arrowRotation < 0 then
		arrowRotation = arrowRotation + 360
	end

	-- Choose a random prize to land on
	local selectedPrize = validPrizes[math.random(#validPrizes)]

	-- Calculate the rotation goal to land on the selected prize
	local rotationDiff = selectedPrize.Position.X.Offset - spinwheel.Rotation % 360
	local selectedRotationGoal = 360 * 5 + arrowRotation + rotationDiff / 2

	-- Tween the Rotation property for a smooth spinning effect
	local rotateTweenGoal = { Rotation = spinwheel.Rotation + selectedRotationGoal }
	local rotateTweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
	local rotateTween = TweenService:Create(spinwheel, rotateTweenInfo, rotateTweenGoal)

	rotateTween:Play()

	wait(3) -- Wait for 3 seconds before stopping the wheel

	-- Stop the wheel immediately
	rotateTween:Cancel()

	-- Give the player the corresponding reward for the won prize
	local reward = RewardsFolder:FindFirstChild(selectedPrize.Name)
	if reward then
		if leaderstats:FindFirstChild("cash") then
			leaderstats.cash.Value = leaderstats.cash.Value + reward.Value
		else
			warn("Cash value not found in leaderstats.")
		end
	else
		warn("Reward not found for prize:", selectedPrize.Name)
	end

	-- Trigger client to update UI or handle the result
	RemoteEvent:FireClient(player, "WheelStopped", selectedPrize)

	isSpinning = false  -- Reset spinning flag after the wheel has stopped
end

RemoteEvent.OnServerEvent:Connect(spinWheel)




Try debugging some stuff, such as printing the rotations and etc.

local rotateTweenGoal = { Rotation = spinwheel.Rotation + 360 * 5 }

actually it rotates to the same value the wheel was initially at (360 degress is 0, 360 * 5 is also 0)

You are always rotating it the same amount? Obviously it will always stop and the same prize.

fr? i thought i changed that…? i’ll take a look at it again

it still does not use the Second ImageLabel Named Prize2

local rotateTweenGoal = { Rotation = spinwheel.Rotation + 360 * 5 }
This stays the same.

i know i did that i gave the updated version of it, and yea again still doesn’t work. it never lands on the other prizes ImageLabels i made in the WheelPrizes folder. and i tried to just make it animate the rotation and only land on those spots but it just won’t do it so i give up lol

fixed it myself, i have a new issue with it though the problem was the rotation calculation i did and yea that whole part was messed up, and because of that one section it’s causing a new issue i can’t figure a fix.

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