My spin wheel wont land on the prize that was chosen

  1. What do you want to achieve? Keep it simple and clear!

  2. when i spin the wheel, it should stop on the chosen reward.

  3. What is the issue? Include screenshots / videos if possible!
    it does not stop on the chosen reward, instead it lands on something totally different.

local plr = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")

script.Parent.Frame.Wheel.SpinButton.Frame.TextLabel.Text = "Spin! (" .. plr.SpinsData.Spins.Value.. ")"

local rewardsTable = {
	[1] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("1"), rarity = 15},
	[2] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("2"), rarity = 5},
	[3] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("3"), rarity = 10},
	[4] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("4"), rarity = 15},
	[5] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("5"), rarity = 10},
	[6] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("6"), rarity = 20},
	[7] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("7"), rarity = 20},
	[8] = {script.Parent.Frame.Wheel.innerpart:FindFirstChild("8"), rarity = 15},
}

local function checkValid()
	local invoke = game.ReplicatedStorage.CheckSpinValid:InvokeServer(plr)
	
	if invoke == true then
		return true
	end
end

local function chooseReward()
	local chance = math.random(1,100)
	local chosenIndex = math.random(1, #rewardsTable)
	local rarity = rewardsTable[chosenIndex].rarity
	
	if chance <= rarity then
		return chosenIndex
	else
		return chooseReward()
	end
end

local REWARD_DEGREE = 45

script.Parent.Frame.Wheel.SpinButton.MouseButton1Click:Connect(function()
	if script.Spinning.Value == false then
		local checkValidSpin = checkValid()

		if checkValidSpin == true then
			script.Spinning.Value = true
			
			local randomRewardIndex = chooseReward()
			print(randomRewardIndex)

			local targetRotationAngle = (randomRewardIndex) * REWARD_DEGREE

			local fullSpins = 3
			local endRotation = (360 * fullSpins) + targetRotationAngle

			local instance = script.Parent.Frame.Wheel.innerpart

			local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0)

			local tween = TweenService:Create(instance, tweenInfo, {
				Rotation = endRotation
			})

			instance.Rotation = 0
			tween:Play()
			script.Spin:Play()
			tween.Completed:Wait()

			script.Spin:Stop()
			script.Win:Play()
			game.ReplicatedStorage.WonSpinWheel:FireServer(randomRewardIndex)
			script.Spinning.Value = false
		end
	end
end)

plr.SpinsData.Spins.Changed:Connect(function()
	script.Parent.Frame.Wheel.SpinButton.Frame.TextLabel.Text = "Spin! (" .. plr.SpinsData.Spins.Value.. ")"
end)

3 Likes

Make it so you have 100% of chance to get a prize and test it 2 times to see if you always land on the same thing. If you do, then adjust it. After make it random again and test if it works.

1 Like

What will that exactly solve? Ive tried this.

I thought maybe there were extra degrees.

There’s 110 percent fully… meaning all the items % sums to 110… I think.

I tried your script and it works really well. When I force it to land on the third index, it always gives me 4:
Capture d’écran 2024-05-20 125458

The first print is the index and the second one is the rotation:
Capture d’écran 2024-05-20 125514

Example: If the index is 3 , then give the player 4 coins, if index is 4 then 5 coins etc.

Alright, well I solved it anyway. thanks for the help though.

Btw I wouldn’t use FindFirstChid() for anything that’s not being checked if it exists. I’d use WaitForChild() since you’re storing the item and it may mess up your script if the game loads slowly.

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