#How do i optimize this?
1 messages · Page 1 of 1 (latest)
try updating them all in 1 big loop maybe
instead of a while loop for each
also try runservice
Try runservice.renderstepped
i will try that
i tried using runserver.renderstepped but it didnt do anything, ill try and get everything into a big loop and see if that works
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
-- code goes here
end)
Did you set it up like this
Heartbeat is probably better to use but if you want it to update every frame use renderstepped
if u have a very long list of cars
u might have to change it so that it only updates the ones that are visible
yes
so if the car guis go like 1,2,3,4,5,6,7,8,9,10 .. and the current car in the middle is 5 then only rotate 4,5,6
u get what i mean
yeah, but i dont know how to check for visible frames
like i said
You there is no way
and im going for jailbreaks old spinning animation on their car spawning from 2019
You must do some math based on the frame sizes
im failing math
jk
i dunno how i would do that tho
?
every 5 frame instead of 1 maybe
:O
Just multiple by the frame size and margine
i can try that
so just an os.clock check
yes but that arises another issue, how would i know the specific frames shown?
Or runservice.heartbeat
ok ok
how did u do the
frames on the bottom going from left to right
right to left
scrollingframe
lemme see if theres api
Ik there's a way I would have to go check
ill check documentation site whilst you do that
local scroll = -- your ScrollingFrame
scroll:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
print("Scroll X:", scroll.CanvasPosition.X)
print("Scroll Y:", scroll.CanvasPosition.Y)
end)
Try that
ok i got an idea
?
divide screen's x size by the size of a cars frame's x size we get the amount of car frames we see in the screen at a time say this value is CarAmount
say CurrentIndex is 1
every time canvasposition's x position changes by the amount of a car frames x size change currentindex by 1
update cars from CurrentIndex - CarAmount/2 to CurrentIndex + CarAmount/2
this assumes cars are placed in a list
the cars are placed in a viewport that lies here
ScrollingFrame -> ViewportFrame -> Model
ah
this?
vehicle.Parent = template
vehicle:PivotTo(CFrame.new(Vector3.new(0,0,0)) * CFrame.fromEulerAngles(math.rad(0),math.rad(180),math.rad(0)))
game:GetService("RunService").Heartbeat:Connect(function()
if template.Visible == false then return end
vehicle:PivotTo(vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0)))
end)
local tempString = vehicle.Name
W9f408f5de:FireServer("ReturnOwnedGarageItems", game.Players.LocalPlayer, tempString)
didnt u turn it into 1 loop?
i havent gotten the chance yet
do that
when the gui opens connect a renderstepped connection
have a list of vehicle models
loop thro the list and update
so in a singular renderstepped, i go through all the items and make them spin?
** You are now Level 5! **
yes
i changed it but the fps still drops
local testList = {}
for _,model in SpawningFrame.VehicleList:GetDescendants() do
if model:IsA("Model") and model.Parent:IsA("ViewportFrame") then
table.insert(testList, model)
end
end
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
for i=1, #testList do
local vehicle = testList[i]
vehicle:PivotTo(vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0)))
end
end)
ok
i gotta eat i will be back in like
30 mins
meanwhile check out
os.clock and try to limit the rate
also this
changed it to do that
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
for i=1, #testList do
local vehicle = testList[i]
vehicle:PivotTo(vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0)))
end
end)
it still drops fps
im thinking of making the spinning into an animation t loops but idk how i would do that
using the tween service to move to a rotation would just find the quickest route of doing that
alright im back
ok first
hmm
i think the core solution would be to only update those visible honestly
yeah
the issue im thinking abt in your example is the fact theres gaps between the items
which could make the one on the edge which is visible not spin
who knew a spinning car would cause this huge issue
aa wait
?
wait
it uses cframe
worldpivot is a cframe
uh
or are they diff for each vehicle
ye check that rq
they are the same
it prints the same positon 20 times (the amount of vehicles i have) then its positon print is different
ok nice
then we can do
local LastUpdate = os.clock()
local UpdateRate = 0.1
local CF = vehicle.WorldPivot
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
if os.clock() - LastUpdate >= UpdateRate then
CF = CF * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0))
for i,v in testList do
v:PivotTo(CF)
end
end
end)
try this
ah mb
local LastUpdate = os.clock()
local UpdateRate = 0.1
local CF = vehicle.WorldPivot
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
if os.clock() - LastUpdate >= UpdateRate then
LastUpdate = os.clock()
CF = CF * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0))
for i,v in testList do
v:PivotTo(CF)
end
end
end)
?
brb
back
so
i would like to give news
it changed the fps
not in a good way ;-;
this is what the imported version you gave me looks like
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
for i=1, #testList do
local vehicle = testList[i]
local LastUpdate = os.clock()
local UpdateRate = 0.1
local CF = vehicle.WorldPivot
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
if os.clock() - LastUpdate >= UpdateRate then
LastUpdate = os.clock()
CF = CF * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0))
for i,v in testList do
v:PivotTo(CF)
end
end
end)
end
end)
i had to put it there cuz vehicle is not defined outside the for loop
import every model into blender, export it back into studio as solid fbx
's
and spin them
noo not like that
less part count
that will make it worse
😭
what
theres a reason the cars arent a solid model ;-;
what
dont tell me so they can drive
the sections need the colors to be able to be customized
YES
they need to drive in the viewport frame 🙏
i am not taking a model and putting it through blender to pull back a solid model for every single car i add to my game bro
then optimize the fucking script
** You are now Level 6! **
what do you think im trying to do
this whole chat is based on optimization
read the title bro ;-;
why are you useing renderstepp
js tween it
ok
it uses the worldpivot since origin is read only
game:GetService("RunService").RenderStepped:Connect(function()
if SpawningFrame.Visible == false then return end
for i=1, #testList do
local vehicle = testList[i]
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local prop = {
WorldPivot = vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-180), math.rad(0))
}
local anim = tweenservice:Create(vehicle, info, prop)
anim:Play()
end
end)
if u do it the tween way
do not
put it in rendersevice
just make 1 tween and play it for each car
no need for a loop
for i=1, #testList do
local vehicle = testList[i]
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local prop = {
WorldPivot = vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-360), math.rad(0))
}
local anim = tweenservice:Create(vehicle, info, prop)
anim:Play()
end
it doesnt move the vehicle at all
just changes the world pivot
why dont u just rotate the camera of viewportframe instead of rotating the model
the camera is offset i dunno how i would do that
and i suck at math
wait
WAIT
i got an idea
u change the camera orientation and position
yeah thats why i said i suck at math, the position would need to be determined
but
i got idea