i have a indicator at the middle of face 1 but when i spin its not accurate to the indicator local soulFragmentRewardsDefault = {
10, 20, 70, 50, 10, 20, 70, 10,
20, 70, 50, 10, 20, 70, 50, 10
}
local spinCost = 10
local active = false
local lastPlayer
local wheelFolder = script.Parent -- The "Wheel" folder
local motor = wheelFolder.Motor:FindFirstChildOfClass("HingeConstraint")
local prompt = wheelFolder.Button:WaitForChild("ProximityPrompt")
local screenPart = wheelFolder:WaitForChild("Screen")
local surfaceGui = screenPart:WaitForChild("ScreenGui")
local label = surfaceGui:WaitForChild("Label")
local function updateScreenText(text)
label.Text = text
end
-- 🎯 Get reward based on adjusted angle (offset aligns with arrow)
local function getReward(angle)
-- Offset by 11.25 degrees so face centers align with arrow
angle = (angle + 11.25) % 360
code
local faceSize = 360 / 16
local faceIndex = math.floor(angle / faceSize) + 1
local localAngle = angle % faceSize
local centerZoneHalfSize = 3
local centerAngle = faceSize / 2
if faceIndex == 1 then
if math.abs(localAngle - centerAngle) <= centerZoneHalfSize then
return 1000
end
elseif faceIndex == 8 then
if math.abs(localAngle - centerAngle) <= centerZoneHalfSize then
return 500
end
end
return soulFragmentRewardsDefault[faceIndex] or 10
end
local function addSoulFragments(player, amount)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local soulFragments = leaderstats:FindFirstChild("Soul Fragments")
if soulFragments and soulFragments:IsA("IntValue") then
soulFragments.Value += amount
end
end
local function awardSoulFragments(player, angle)
local reward = getReward(angle)
addSoulFragments(player, reward)
return reward
end
local function spinWheel()
updateScreenText("Spinning...")
motor.MotorMaxAcceleration = 10
motor.AngularVelocity = 10 + math.random()
task.wait(2 + 3 * math.random())
motor.MotorMaxAcceleration = 1
motor.AngularVelocity = 0
task.wait(10) -- wait for wheel to settle
code
local reward = awardSoulFragments(lastPlayer, motor.CurrentAngle)
updateScreenText("You won " .. reward .. " Soul Fragments! Press E to spin again.")
active = false
prompt.Enabled = true
end
prompt.Triggered:Connect(function(player)
if active then return end
code
local stats = player:FindFirstChild("leaderstats")
if not stats then return end
local soulFragments = stats:FindFirstChild("Soul Fragments")
if not soulFragments then return end
if soulFragments.Value >= spinCost then
soulFragments.Value -= spinCost
lastPlayer = player
active = true
prompt.Enabled = false
task.spawn(spinWheel)
else
updateScreenText("You need at least " .. spinCost .. " Soul Fragments to spin!")
end
end)
-- Initial screen text
updateScreenText("Ready to play!")
Assistant
To ensure the wheel stops accurately and aligns with the indicator, here's the revised code with explanations:
Key Changes:
Faster Deceleration: Increase MotorMaxAcceleration when stopping to halt the wheel quickly.
Dynamic Wait: Use a loop to wait until the wheel stops moving instead of a fixed delay.
Offset Adjustment: Ensure the offset correctly centers the indicator.
lua
local function spinWheel()
updateScreenText("Spinning...")
motor.MotorMaxAcceleration = 10 -- Slightly higher initial acceleration
motor.AngularVelocity = 10 + math.random() -- Initial spin speed
task.wait(2 + 3 * math.random()) -- Spin duration
-- Rapid deceleration to stop quickly
motor.MotorMaxAcceleration = 100 -- High acceleration for fast stopping
motor.AngularVelocity = 0
-- Wait until the wheel stops moving
repeat
task.wait(0.1)
until math.abs(motor.AngularVelocity) < 0.1 -- Check for near-zero velocity
-- Read the final angle immediately after stopping
local reward = awardSoulFragments(lastPlayer, motor.CurrentAngle)
updateScreenText("You won " .. reward .. " Soul Fragments! Press E to spin again.")
active = false
prompt.Enabled = true
end
Explanation:
Faster Deceleration: By setting MotorMaxAcceleration to 100 when stopping, the wheel decelerates rapidly, minimizing drift.
Dynamic Wait: The loop checks the angular velocity until it's near zero, ensuring the wheel has stopped before reading the angle.
Immediate Angle Capture: The angle is read right after stopping, avoiding drift during an arbitrary delay.
Additional Notes:
The initial MotorMaxAcceleration was slightly increased to 10 for smoother acceleration during the spin.
The math.abs check ensures both positive and negative residual velocities are accounted for.
This approach should align the wheel's final position accurately with the indicator.