What script can make a wheel spin?

Hey guys!

I think y’all know that there are some models with a Wheel that you can spin. With that, I wanted to know what scripts I can put to this one.

image

*(Image from my project)

I have no idea some type of stuffs people say like “You should use CFrame” (I don’t know what CFrame means) because I don’t have that ability of programming, only building.

If you guys know what scripts I can put, I really appreciate your amazing help.

Thanks!

1 Like

You should use CFrame Tweening, Since I’m assuming you don’t know how to do that I’ll link some wiki articles on it.

CFrame: CFrame | Documentation - Roblox Creator Hub
Tweening: TweenService | Documentation - Roblox Creator Hub

Thats what I do when I rotate things, I Either use CFrame or Tweening or a conjunction of both.

1 Like

I have made a sample script, as full rotations with TweenService are a bit tricky. (Tween will always use shortest way to reach its goal, so in best case scenario you will only achieve half turn). To make full rotations you will need multiple tweens. I am also assuming you want your “Wheel of fortune” to slow down? Here is what I came up with (parent the script to the part, and make sure it is Anchored):

local part = script.Parent
local TweenService = game:GetService("TweenService")
local slowestSpeed = 1
local spinStep = math.pi/36 --three steps per section
local friction = 0.5 --percent per step

local function Spin(initialSpeed)
	
	if initialSpeed <= slowestSpeed then
		return
	end
	local speed = initialSpeed
	local style = TweenInfo.new(1/speed,Enum.EasingStyle.Linear)
	local target = {CFrame = part.CFrame * CFrame.Angles(0,spinStep,0)}
	local tween = TweenService:Create(part,style,target)

	local connection

	local function OnCompletion()
		
		connection:Disconnect()
		speed = speed - (initialSpeed*friction/100)
		if speed < slowestSpeed then
			return
		end
		style = TweenInfo.new(1/speed,Enum.EasingStyle.Linear)
		target = {CFrame = part.CFrame * CFrame.Angles(0,spinStep,0)}
		tween = TweenService:Create(part,style,target)
		
		connection = tween.Completed:Connect(OnCompletion)
		tween:Play()
	end

	connection = tween.Completed:Connect(OnCompletion)
	tween:Play()
	
end

Spin(50+math.random(50))

Hope this helps.

The Wheel is 100% Anchored, what I need it was the script

Tysm for putting the script! I will test the wheel and see what will happend

Well uhhh… I don’t know what happened to the wheel but looks very funny :rofl: :rofl:

1 Like

I’m pretty sure thats because you are making the wheel spin the wrong way. (Check your script) Also, CFrame stands for coordinate frame.

1 Like

Change the rotation axis in both targets. It will be either CFrame.Angles(spinStep,0,0) or CFrame.Angles(0,0,spinStep) depending on the wheel initial orientation.

2 Likes

The orientation from the wheel is 0, -90, 90