Increasingly Slow Moving Parts

I’m currently experimenting with moving parts, and I came to notice that forever how long I’m in the game the moving parts become increasingly slower.

Then:

5 Minutes After:

I have no clue what is happening here so please give me information about this.
Sorry if its hard to notice

Show me the code. It may have something to do with this.

image

It must be on roblox’s end then. Server lag, maybe? Not sure. Your code looks good to me.

I don’t know if this is what is causing the problem but there is a huge memory leak here.

while wait() do
for i, v in pairs(folder:GetChildren()) do
    if v:IsA("BasePart") then
        v.CFrame = v.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0.0)
        v.Touched:Connect(function(hit) -- This is where it is (You are setting up a hit connection every time the code loops)
            if hit.Parent:FindFirstChild("Humanoid") then
                hit.Parent.Humanoid.Health = 0
                end
            end)
        end
    end
end

Another thing is the spinner move according to the server FPS. I would recommend using runservice instead to make sure it runs consistently.

1 Like

Try this:

local TweenService = game.TweenService

TweenService:Create(v, TweenInfo.new(
	1, -- Time to Complete
	Enum.EasingStyle.Linear, -- Standard Linear
	Enum.EasingDirection.InOut, -- In case if you want a Different Style, use this
	-1 -- So it repeats forever
	), {Orientation = Vector3.new(0,360,0)}):Play()

Should be more smoother

Edit: New Script

local TweenService = game.TweenService


local A = TweenService:Create(v, TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut
			), {Orientation = v.Orientation + Vector3.new(0,360,0)})
		A.Completed:Connect(function()
			A:Play()
			
		end)
		A:Play()

	

Personally i would not do this due to the fact that tweens can strain performance and with 10+ spinners, it’s possible you could see the servers Fps dropping.

Personally I have never had this happen. I don’t have a good monitor

Do you really need to make v.Touched connections so much? It’s most likely server lag for the thousands of redundant connections eating up memory. You could follow a proposed solution of this reply and use runservice

local Run = game:GetService("RunService")
local folder = --the folder full of spinners

local SpinSpeed = 15 --15 degrees per second 

for _, spinner in folder:GetChildren() do
   spinner.Touched:Connect(function() --establish a connection for each spinner ONCE only
      --do the hurting
   end)
end

Run.Heartbeat:Connect(function(delta)
   for _, spinner in folder:GetChildren() do
      spinner.CFrame *= CFrame.Angles(0, math.rad(delta * SpinSpeed), 0)
   end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.