I’ve always wondered which of the 2 is better, I know that by using the runtime service everything should be more stable, but doing some tests I saw that it actually consumes more memory, can anyone give me an opinion on this? I attach a piece of code and some screen shots
while task.wait()
local position = script.Parent.PrimaryPart.Position.Y
local maxPosition = position + 5
local flag = false
while task.wait() do
if script.Parent.PrimaryPart.Position.y < maxPosition and flag == false then
script.Parent.PrimaryPart.CFrame = script.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0.01,0) * CFrame.new(0,0.1,0)
else
flag = true
script.Parent.PrimaryPart.CFrame = script.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,0.01,0) * CFrame.new(0, -0.1, 0)
if script.Parent.PrimaryPart.Position.y <= position then
flag = false
end
end
end
RunTimeService
local position = script.Parent.PrimaryPart.Position.Y
local maxPosition = position + 5
local movingUp = true
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if script.Parent.PrimaryPart.Position.Y < maxPosition and movingUp then
script.Parent.PrimaryPart.CFrame = script.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0, 0.01, 0) * CFrame.new(0, 0.1, 0)
else
movingUp = false
script.Parent.PrimaryPart.CFrame = script.Parent.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0, 0.01, 0) * CFrame.new(0, -0.1, 0)
if script.Parent.PrimaryPart.Position.Y <= position then
movingUp = true
end
end
end)
This is with RunTime Script
This is with While task.wait()