Spinny Problems

Greetings, recently I’m trying to make a windmill’s blades rotate so it looks realistic. I tried making this script and it just doesn’t work, no output response.

--< Variables >-- 

local models = {script.Parent.Blades, script.Parent.MotorConnect}

--//

while true do

for i = 0,360,1 do
	wait()
	
	for i,v in pairs(models) do
		
		v.Orientation = Vector3.new(0,0,i)
		
	end
end
end
2 Likes

Is this a server script? Have you tried debugging, like print()ing all over the script?

2 Likes

You can’t set a model’s position like that. You have to set a primary part for the model you’re spinning and then use :SetPrimaryPartCFrame(cf).

What I would do is something like bladeModel:SetPrimaryPartCFrame(bladeModel:GetPrimaryPartCFrame() * CFrame.Angles(0,0,math.rad(1))

1 Like

Adding onto that -

I would try doing something like this:

local models = {script.Parent.Blades, script.Parent.MotorConnect} 
local i = 0
while wait(0.01) do
i = i + 1
for i,v in pairs(models) do 
v:SetPrimaryPartCFrame(CFrame.new(v.PrimaryPart.Position)*CFrame.Angles(0,0,math.rad(i))
end
end

(This script would affect every model in the “models” array)

1 Like

Good news, it spins, but it continues spinning until it reaches terminal velocity and slows down, I want it to have a stable speed, how could I make that?

1 Like

Do you have a video? The code they provided should be constant speed, unless you’ve done something strange when implementing it.

If you provide the code we can check.

1 Like

Here’s a good video tutorial that shows how to achieve this without code:

You could also try something like this:


while true do

for i = 0,360 do
	wait()
	
	for i,v in pairs(models) do
		
		v.CFrame= CFrame.new(v.Position)*CFrame.Angles(0,0,math.rad(i))
		
	end
end

end


2 Likes

I try to avoid loops when I can, heres a solution that I made a couple of days ago

L1LUtEB3iK

local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")

local tweenInfo = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)

local function setupKillBeam(killBeam)
	TweenService:Create(killBeam, tweenInfo, {Orientation = Vector3.new(-90, 180, 0)}):Play()

	killBeam.Touched:Connect(function(part)
		local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
		if not humanoid then return end
		humanoid.Health = 0
	end)
end


for _, tagged in ipairs(CollectionService:GetTagged("KillBeam")) do
	setupKillBeam(tagged)
end

heres the model it doesn’t include the script, you would need to copy the above code into a server script and place it in ServerScriptService
Spin.rbxm (3.0 KB)

3 Likes

By what is this kind of decision informed by? Inbuilt services aren’t always the most optimized, particularly those concerning CFraming multiplication can be sheared off with raw operations from what I’ve observed. Was this informed by doing the alternative operations en masse and seeing the run times?

1 Like

I just make use of roblox services whenever I can, I’ve just gotten into a habit of not using loops, because doing the same operation over and over usually isn’t the better solution

I have no idea if using TweenService over a loop is more efficient in this case, I didn’t do any tests, but it is easier to understand and read imo

2 Likes

TweenService or animations are always better than just doing CFrame on the server. TweenService endures every client gets a smooth version.

If you’re doing it on the client then there isn’t as much difference, but I’d still say TweenService wins if you can use it directly.

1 Like

@httpDerpyy I recommend using RunServices’ RenderStepped event to rotate the model tbh. (inside of a local script, the local script must be outside of the workspace)

game:GetService("RunService").RenderStepped:Connect(function()
      model.PrimaryPart.CFrame = model.PrimaryPart.CFrame * CFrame.Angles(0,0,math.rad(0.5))
end)

this will rotate the model smoothly with the Client, I don’t believe that the server should handle any object animations.