-
What do you want to achieve? Keep it simple and clear!
-
when i spin the wheel, it should stop on the chosen reward.
-
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)