I’m also trying to make this whole thing in the style of old school Roblox (with the studs, no smooth animations and all that.)
What do you want to achieve? I want to make a fan that oscillates
What is the issue? I can’t figure out how to make “for i = [Numbers here] do loop” start going backwards and then go back into it’s original position.
What solutions have you tried so far? I’ve looked in a-lot of places; Roblox Dev-forums, Youtube & Google, nothing I’ve found has helped. I’m completely at a loss (Probably because my brain just stops functioning whenever I see all these bigger codes and scripts that have nothing to do with what I’m trying to make)
Here’s the code that I have so far and what it does (as seen in the video):
local model = script.Parent
local rad = math.rad
local rotateAmount = 1
for i = 1, 25 do
task.wait(0.25)
local newCFrame = model.PrimaryPart.CFrame * CFrame.Angles(0,rad(rotateAmount),0)
model:SetPrimaryPartCFrame(newCFrame)
end
local model = script.Parent
local rotateAmount = 1
-- We will use a function and a coroutine so you can write other code to this script as well
local function loop()
-- This will make a forever loop, no for loops required
while true do
-- You should use :PivotTo instead of :SetPrimaryPartCFrame
model:PivotTo(model.WorldPivot * CFrame.Angles(0, math.rad(rotateAmount), 0))
task.wait(0.25)
end
end
task.defer(loop)
You can use a sine wave to create an oscillation effect with math.sin. Then, for animation, you want this to run smooth so the rotation should be updated every second. For this, you can use RunService.
In this code, I used RenderStepped, which can only be used on the client. This is because animations like this should be done on the client, and not the server to make the animation more performant. If you absolutely need to run this on the server (which I do not recommend), switch out RenderStepped for Heartbeat.
local RunService = game:GetService("RunService")
local model = workspace.Model
local rotateAmount = 60 -- in degrees
local deltaTime = 0
RunService.RenderStepped:Connect(function(dt)
local rot = math.sin(deltaTime) * (rotateAmount * dt)
model:PivotTo(model:GetPivot() * CFrame.Angles(0, math.rad(rot), 0))
deltaTime += dt
end)
I’m not sure what I’m doing wrong but this script doesn’t seem to work unless I change RenderStepped to Heartbeat. Not to mention that the rotation is smooth (which is not what I wanted.)
Do I put the script into the model itself? (I named the model: FanTest)
Should it be a Local Script or just a regular Script?
How do I make the rotation not smooth?