I need help with Tween part

Im trying to make a part rotate when clicked, im using TweenService and when i click it, it like spins around a bunch before going to its final destination, im trying to make it turn 45 degrees each click, heres my script:

local TweenService = game:GetService("TweenService")
local part = script.Parent
local clickDetector = part:WaitForChild("ClickDetector")


local tweenInfo = TweenInfo.new(
	1,           
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.InOut,
	0,              
	false,            
	0                 
)


local currentRotation = part.Orientation

local function rotatePart()

	local targetRotation = currentRotation + Vector3.new(0, 45, 0)

	
	local tweenGoal = {
		Orientation = targetRotation
	}

	
	local tween = TweenService:Create(part, tweenInfo, tweenGoal)


	tween:Play()

	
	tween.Completed:Connect(function()
		currentRotation = targetRotation
	end)
end


clickDetector.MouseClick:Connect(rotatePart)
1 Like

I would use CFrame instead of Orientation. Set it up like this:

local TweenService = game:GetService("TweenService")
local part = script.Parent
local clickDetector = part:WaitForChild("ClickDetector")

local tweenInfo = TweenInfo.new(
	1,           
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.InOut,
	0,              
	false,            
	0                 
)

local currentCFrame = part.CFrame

local function rotatePart()
	local targetCFrame = currentCFrame * CFrame.Angles(0, math.rad(45), 0)
	
	local tweenGoal = {
		CFrame = targetCFrame
	}

	local tween = TweenService:Create(part, tweenInfo, tweenGoal)

	tween:Play()

	tween.Completed:Connect(function()
		currentCFrame = targetCFrame
	end)
end

clickDetector.MouseClick:Connect(rotatePart)

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