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
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)
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?
I try to avoid loops when I can, heres a solution that I made a couple of days ago
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)
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?
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
@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)