#game lagging

1 messages · Page 1 of 1 (latest)

atomic raptor
#
local pull = rs2.Heartbeat:Connect(function()
            for _, obj in ipairs(breakables) do
                local distance = (tornado.Position - obj.Position).Magnitude
                if obj:IsA("BasePart") and obj.Anchored == false and distance <= 45 then
                    local dir = ( tornado.Position - obj.Position)
                    local force = math.clamp(obj.Mass,30,40)
                    local rotation = math.clamp(obj.Mass,20,30)
                    obj.AssemblyLinearVelocity = dir.Unit * force
                    obj.AssemblyAngularVelocity = dir.Unit * rotation
                elseif obj.Anchored == true and distance <= 45 then
                    obj.Anchored = false
                end
            end

``` how could i optimize this?, it lags alot since there is alot of parts but i dont want to loose smoothness, it is only a part of the code but its only the necessary ig
plucky drift
#

Instead of looping through everything you could only loop through those who are in range using workspace:GetPartBoundsInRadius and it also uses overlapParams

vague pagoda
#

i wonder why this heartbeat on god knows how many parts with heavy physics work is lagging

#

theres no optimizing this you gotta change the approach