Tween Service glitching out

Hello!

My tween snaps to a rotation once it turns 180 degrees.

Script:

local TweenService = game:GetService("TweenService")
local function createTween(part)
	local tweenInfo = TweenInfo.new(
		1.5, -- Time
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.InOut, -- EasingDirection
		-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
		false, -- Reverses (tween will reverse once reaching its goal)
		0 -- DelayTime
	)

	local goal = {}
	goal.CFrame = part.CFrame * CFrame.Angles(0, math.pi, 0)-- Spin 360 degrees

	local tween = TweenService:Create(part, tweenInfo, goal)
	tween:Play()
end

local CorrodeLure = script.Parent["Corroded Lure"]
createTween(CorrodeLure)

local BegginnersLure = script.Parent["Begginner's Lure"]
createTween(BegginnersLure)

local FrailLure = script.Parent["Frail Lure"]
createTween(FrailLure)

local PaperLure = script.Parent["Paper Lure"]
createTween(PaperLure)

local CopperLure = script.Parent["Copper Lure"]
createTween(CopperLure)

local SwiftLure = script.Parent["Swift Lure"]
createTween(SwiftLure)

local BlessedLure = script.Parent["Blessed Lure"]
createTween(BlessedLure)

pi is 180 degrees. you need two pi

How would I do that?


fix it to
goal.CFrame = part.CFrame * CFrame.Angles(0, math.pi * 2, 0)

1 Like

now the parts don’t move.


also because a 360 rotation will output the same CFrame so the part will not move
you can try tween the Orientation instead

1 Like

Can you represent that in code form?

local goal = { Orientation = Vector3.new(0, 360, 0) }

would be better if you just using RunService in stead of tweenService since the proforment of tweenservice is kinda bad

local function createRot(part)
    local rotationSpeed = math.pi * 2 -- 360 degrees per second
    
    local connection
    connection = game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
        -- Rotate a bit each frame based on delta
        part.CFrame = part.CFrame * CFrame.Angles(0, rotationSpeed * deltaTime, 0)
    end)
end

local lures = {
    script.Parent["Corroded Lure"],
    script.Parent["Begginner's Lure"],
    script.Parent["Frail Lure"],
    script.Parent["Paper Lure"],
    script.Parent["Copper Lure"],
    script.Parent["Swift Lure"],
    script.Parent["Blessed Lure"]
}

for _, lure in pairs(lures) do
    createRot(lure)
end

but still you could make it better via making all the part spin in just one heartbeat but it just a demo i didnt test it

2 Likes
local timeForFullCycle = 1.5
local targetRotPerCycle = 360

local partsToRotate = {
	script.Parent["Corroded Lure"],
	script.Parent["Begginner's Lure"],
	script.Parent["Frail Lure"],
	script.Parent["Paper Lure"],
	script.Parent["Copper Lure"],
	script.Parent["Swift Lure"],
	script.Parent["Blessed Lure"],
}

game["Run Service"].Heartbeat:Connect(function(delta)
	local rot = (targetRotPerCycle/timeForFullCycle)*delta
	for i,v in partsToRotate do
		if v:IsA("BasePart") then
			v.Orientation += Vector3.new(0, rot, 0) -- modify the axis to your needs
		end
	end
end)

This should rotate the parts in partsToRotate for each heartbeat.

2 Likes

Thanks! Now my parts spin fine!

Also how do you slow down the part?

It is a bit too fast.

    math.pi * 2  -- = 1 full rotation per second
    math.pi       -- = 1/2 rotation per second
    math.pi / 2  -- = 1/4 rotation per second
2 Likes

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