#how would i optimize/replace constantly udpating viewportframe cuz its too laggy
1 messages · Page 1 of 1 (latest)
said code
sigma, il update it, to what degree do u want it done? opt 2, instructions aswell?
its just a wuestion
uhh
viewports are laggy, any alternatives?
or ways to not lag
if 1 have 1 viewport updating a room every 0.1s its laggy
let me look into the engine
is this a bot?
wait have u tried lazy viewport?
how much and how often does it change?
no whats that
** You are now Level 8! **
u disabled it if the room doesn't change
every 0.1s but its not that important so i can change it
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
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
pastebin would be nice
btw how do i type code like others
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.
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```
and end it with ```
enter after lua
and then paste ur code
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
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.
alr
give me a minute im rewriting ur code
also the -5k is why u cant see dummies im assuming
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
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```
** You are now Level 7! **
here ran it through stylua aswell
also make use of loops bro, u dont need all those if's
alr tysm
if that doesn't run as fast, lmk i have an idea on how to make it faster
ok
its still a poll, there is a dookie solution i came up with, so if it runs fine i wont give it
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
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