Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make this wheel rotate smoothly with "for i"?

Asked by 2 years ago
Edited 2 years ago

So, i've created a pipe wheel, and when the player presses "E" then it rotates but now, it just spins somewhere instantly, not smoothly. Here's the code:

local prox = script.Parent.wheel.Union.ProximityPrompt

prox.Triggered:Connect(function()
    for i = 1, 100, 1 do
        script.Parent.wheel.Union.CFrame = script.Parent.wheel.Union.CFrame * CFrame.fromEulerAnglesXYZ(0.5,0,0) * CFrame.new(0, 0, 0)

    end
end)
0
Maybe try an animation for the wheel if that's possible theking66hayday 841 — 2y

2 answers

Log in to vote
0
Answered by
Jac_00b 157
2 years ago

You need to add a wait() after one run-through of the loop (line 6). Currently it does not wait after doing a cycle so it will instantly run the loop and finish within a fraction of a second. If it is still too fast, increase the wait time, but the more you increase it the choppier it will become.

Ad
Log in to vote
0
Answered by 2 years ago

A more elegant solution would be to use tweening, which is a built-in system for smooth changes.

Not sure I got the pathing correct since I was using a part with a script under it for my setup but otherwise it works

local prox = script.Parent.wheel.Union.ProximityPrompt
local tweenService = game:GetService("TweenService")

local rotationTime = 5

local tweeningInformation = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)

prox.Triggered:Connect(function()
    local tweenProperties = {
        CFrame = script.Parent.wheel.Union.CFrame * CFrame.Angles(math.rad(180),0,0) * CFrame.new(0, 0, 0)

    }
    local Tween = tweenService:Create(script.Parent.wheel,tweeningInformation,tweenProperties)
    Tween:Play()
end)

Answer this question