#how would i optimize/replace constantly udpating viewportframe cuz its too laggy

1 messages · Page 1 of 1 (latest)

empty citrus
#

image unrelated

slate kraken
#

sigma, il update it, to what degree do u want it done? opt 2, instructions aswell?

empty citrus
#

its just a wuestion

slate kraken
empty citrus
#

viewports are laggy, any alternatives?

#

or ways to not lag

#

if 1 have 1 viewport updating a room every 0.1s its laggy

slate kraken
#

let me look into the engine

empty citrus
#

is this a bot?

slate kraken
#

yes

#

i would reprot it but its been here for a while

#

stfu

#

ffs

#

😭

slate kraken
#

how much and how often does it change?

empty citrus
#

no whats that

deft foxBOT
#

studio** You are now Level 8! **studio

slate kraken
empty citrus
#

every 0.1s but its not that important so i can change it

slate kraken
#

i swear, there is really no need for it to be laggy, i would need to look into ur specific design

#

to see what mistakes u have made

empty citrus
#

alr i can send code

#

opening studio rn

#

its the code, the surfacegui and the adornee for the ui. The uis adornee is the hole part

#

theres prob a error in the code cuz i cant see the dummy but its still unoptimesed even with only 7 dummys inside

slate kraken
#

pastebin would be nice

empty citrus
#

btw how do i type code like others

slate kraken
#

ditch the task.wait loop and use GetPropertyChangedSignal instead, that way it only re-renders when something actually moves. also trim whatever youre cloning into the WorldModel, no need to clone parts that arent even visible in the viewport.

empty citrus
#
cam.CFrame = script.Parent.Adornee.CFrame
script.Parent.ViewportFrame.CurrentCamera = cam
while task.wait(0.1) do
    for i,v in pairs(script.Parent.ViewportFrame:GetChildren()) do
        v:Destroy()
    end
    warn(script.Parent.Adornee.Parent.Name)
    local vectore = Vector3.new(script.Parent.Adornee.Parent.Position.X,-5000,script.Parent.Adornee.Parent.Position.Z)
    print(vectore)
    
    

    
    for i,v in pairs(workspace:GetPartBoundsInRadius(vectore,150)) do
        warn(v)
        if v.Name == "Torso" and v.Parent:FindFirstChild("Humanoid") then
            local clone = game.ReplicatedStorage.domain.DomainHoleDummy:Clone()
            clone.Parent = script.Parent.ViewportFrame
            if v.Parent:FindFirstChild("Left Arm") then
                clone["Left Arm"].CFrame = v.Parent["Left Arm"].CFrame
            end
            if v.Parent:FindFirstChild("Right Arm") then
                clone["Right Arm"].CFrame = v.Parent["Right Arm"].CFrame
            end
            if v.Parent:FindFirstChild("Right Leg") then
                clone["Right Leg"].CFrame = v.Parent["Right Leg"].CFrame
            end
            if v.Parent:FindFirstChild("Left Leg") then
                clone["Left Leg"].CFrame = v.Parent["Left Leg"].CFrame
            end
            if v.Parent:FindFirstChild("Torso") then
                clone["Torso"].CFrame = v.Parent["Torso"].CFrame
            end
            if v.Parent:FindFirstChild("Head") then
                clone["Head"].CFrame = v.Parent["Head"].CFrame
            end
        end
    end

end```
slate kraken
#

and end it with ```

#

enter after lua

#

and then paste ur code

empty citrus
#

most parts are visible in the viewport becouse of the viewport casting in a 150 studs ball

#

and its guaranteed to be on the edge

slate kraken
#

fair enough, but you're still destroying and recloning every single tick which is the expensive part. just move the existing clones instead of nuking them each loop.

empty citrus
#

alr

slate kraken
#

give me a minute im rewriting ur code

#

also the -5k is why u cant see dummies im assuming

empty citrus
#

its not

#

a have a "domain" wich grabs everyone inside a bubble and puts them at -5k to have a bigger interior and better visuals

slate kraken
#

here u go, i formatted it for u aswell

#

i fixed a couple of issues

#

wait that one removed -5k

#
local cam = Instance.new("Camera")
cam.CFrame = script.Parent.Adornee.CFrame
script.Parent.ViewportFrame.CurrentCamera = cam

local clonePool = {}

while task.wait(0.1) do
    cam.CFrame = script.Parent.Adornee.CFrame

    warn(script.Parent.Adornee.Parent.Name)

    local adorneeParent = script.Parent.Adornee.Parent
    local vectore = Vector3.new(adorneeParent.Position.X, -5000, adorneeParent.Position.Z)
    print(vectore)

    local found = {}

    for i, v in pairs(workspace:GetPartBoundsInRadius(vectore, 150)) do
        warn(v)
        if v.Name == "Torso" and v.Parent:FindFirstChild("Humanoid") then
            local character = v.Parent
            found[character] = true

            if not clonePool[character] then
                local clone = game.ReplicatedStorage.domain.DomainHoleDummy:Clone()
                clone.Parent = script.Parent.ViewportFrame
                clonePool[character] = clone
            end

            local clone = clonePool[character]

            for _, limbName in pairs({"Head", "Torso", "Left Arm", "Right Arm", "Left Leg", "Right Leg"}) do
                if character:FindFirstChild(limbName) then
                    clone[limbName].CFrame = character[limbName].CFrame
                end
            end
        end
    end

    for character, clone in pairs(clonePool) do
        if not found[character] then
            clone:Destroy()
            clonePool[character] = nil
        end
    end
end```
deft foxBOT
#

studio** You are now Level 7! **studio

slate kraken
#

here ran it through stylua aswell

#

also make use of loops bro, u dont need all those if's

empty citrus
#

alr tysm

slate kraken
#

if that doesn't run as fast, lmk i have an idea on how to make it faster

empty citrus
#

ok

slate kraken
# empty citrus ok

its still a poll, there is a dookie solution i came up with, so if it runs fine i wont give it

empty citrus
#

still lags

#

its every 0.1s that it lags so it has to do with the updating

#

tried with 23 dummys (138 parts) but they were still and shouldnt have a need to update

#

but i gotta quit studio for now and can only text

slate kraken
#
local RunService = game:GetService("RunService")

local cam = Instance.new("Camera")
cam.CFrame = script.Parent.Adornee.CFrame
script.Parent.ViewportFrame.CurrentCamera = cam

local clonePool = {}
local LIMBS = {"Head", "Torso", "Left Arm", "Right Arm", "Left Leg", "Right Leg"}

RunService.PostSimulation:Connect(function()
    cam.CFrame = script.Parent.Adornee.CFrame

    local adorneeParent = script.Parent.Adornee.Parent
    local vectore = Vector3.new(adorneeParent.Position.X, -5000, adorneeParent.Position.Z)

    local found = {}

    for i, v in pairs(workspace:GetPartBoundsInRadius(vectore, 150)) do
        if v.Name == "Torso" and v.Parent:FindFirstChild("Humanoid") then
            local character = v.Parent
            found[character] = true

            if not clonePool[character] then
                local clone = game.ReplicatedStorage.domain.DomainHoleDummy:Clone()
                clone.Parent = script.Parent.ViewportFrame
                clonePool[character] = clone
            end

            local clone = clonePool[character]
            for _, limbName in pairs(LIMBS) do
                if character:FindFirstChild(limbName) then
                    clone[limbName].CFrame = character[limbName].CFrame
                end
            end
        end
    end

    for character, clone in pairs(clonePool) do
        if not found[character] then
            clone:Destroy()
            clonePool[character] = nil
        end
    end
end)```
#

try this

#

experimental its after physics

#

so hopefully through its finality, ur good

empty citrus
#

Ty

#

Cant try it cuz i need to sleep but will try later