#How do i optimize this?

1 messages · Page 1 of 1 (latest)

loud herald
#

I want to have every model spin at the same speed but it drops the fps from 240 to 120

(Vehicle is just a model)

Code:

                    while task.wait() do
                        vehicle:PivotTo(vehicle.WorldPivot * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(-0.5), math.rad(0)))
                    end
                end)```
trail drift
#

try updating them all in 1 big loop maybe

#

instead of a while loop for each

#

also try runservice

charred nacelle
#

Try runservice.renderstepped

loud herald
#

i will try that

loud herald
charred nacelle
#
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
-- code goes here
end)
charred nacelle
#

Heartbeat is probably better to use but if you want it to update every frame use renderstepped

trail drift
#

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

loud herald
trail drift
#

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

loud herald
trail drift
#

like i said

charred nacelle
loud herald
#

and im going for jailbreaks old spinning animation on their car spawning from 2019

trail drift
#

any change after

#

1 loop

charred nacelle
#

You must do some math based on the frame sizes

loud herald
#

jk

#

i dunno how i would do that tho

trail drift
#

lets try an easier solution

#

limit the update rate

loud herald
#

?

trail drift
#

every 5 frame instead of 1 maybe

loud herald
#

:O

charred nacelle
loud herald
#

i can try that

trail drift
#

so just an os.clock check

loud herald
charred nacelle
#

Or runservice.heartbeat

trail drift
#

how did u do the

#

frames on the bottom going from left to right

#

right to left

loud herald
#

scrollingframe

trail drift
#

lemme see if theres api

loud herald
#

with horizontal canvas

#

dang my internet takes like 5 seconds to send a message

#

😭

charred nacelle
loud herald
trail drift
#

print

#

CanvasPosition

#

while u scroll

#

see if that changes

charred nacelle
#

Try that

trail drift
#

ye ok

#

gah i think we'll have to do some math

trail drift
#

ok i got an idea

loud herald
trail drift
#

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

loud herald
#

the cars are placed in a viewport that lies here

trail drift
#

wait

#

show ur whole update code rq

loud herald
#

ScrollingFrame -> ViewportFrame -> Model

loud herald
#

too long of a message

trail drift
#

no not the whole

#

just the

#

renderstepped inside

loud herald
#

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)
trail drift
#

didnt u turn it into 1 loop?

loud herald
#

i havent gotten the chance yet

trail drift
#

do that

loud herald
#

ive been respondin lol

#

aight

trail drift
#

when the gui opens connect a renderstepped connection

#

have a list of vehicle models

#

loop thro the list and update

loud herald
#

so in a singular renderstepped, i go through all the items and make them spin?

limber thunderBOT
#

studio** You are now Level 5! **studio

loud herald
#

yay lvl 5

#

im more yellow

loud herald
#

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)
trail drift
#

i gotta eat i will be back in like

#

30 mins

#

meanwhile check out

#

os.clock and try to limit the rate

loud herald
# trail drift yes

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

trail drift
#

alright im back

#

ok first

#

hmm

#

i think the core solution would be to only update those visible honestly

loud herald
#

yeah

#

the issue im thinking abt in your example is the fact theres gaps between the items

trail drift
#

oh ye that could cause problems

#

hmm

loud herald
#

which could make the one on the edge which is visible not spin

#

who knew a spinning car would cause this huge issue

trail drift
#

aa wait

loud herald
#

?

loud herald
#

holy crap

#

it just moves all of them like its one thing

trail drift
#

though its not for models

#

which is annoying

#

gah

loud herald
#

GOD DANG IT

#

wait

trail drift
#

wait

loud herald
#

it uses cframe

trail drift
#

print position of

#

vehicle 1 and 2 for me

loud herald
#

worldpivot is a cframe

trail drift
#

like are the

#

positions same

loud herald
#

uh

trail drift
#

or are they diff for each vehicle

loud herald
#

oh

#

they shouldnt but i can check

trail drift
#

ye check that rq

loud herald
#

they are the same

#

it prints the same positon 20 times (the amount of vehicles i have) then its positon print is different

trail drift
#

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)

loud herald
#

?

trail drift
#

there we go forgot something

#

fixed it

#

try this

loud herald
#

brb

#

back

#

so

#

i would like to give news

#

it changed the fps

#

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

heavy cradle
#

's

#

and spin them

heavy cradle
#

less part count

trail drift
#

that will make it worse

trail drift
#

do not put it inside

#

the loop

#

i sent u the loop itself

heavy cradle
loud herald
heavy cradle
#

dont tell me so they can drive

loud herald
#

the sections need the colors to be able to be customized

loud herald
heavy cradle
#

they need to drive in the viewport frame 🙏

loud herald
#

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

heavy cradle
limber thunderBOT
#

studio** You are now Level 6! **studio

loud herald
#

this whole chat is based on optimization

#

read the title bro ;-;

heavy cradle
#

js tween it

loud herald
#

ok

loud herald
# heavy cradle why are you useing renderstepp

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)
trail drift
#

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

loud herald
#

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

glass moat
loud herald
#

and i suck at math

#

wait

#

WAIT

#

i got an idea

glass moat
loud herald
#

but

#

i got idea

loud herald
#

i dont wanna use ai

#

i wanna learn ;-;

glass moat
#

U cant learn if u cant progress, if u use AI wisely and learn how it work, u'd progress

#

even seniors use AI , it's not a biggie as long u understand what does it do