How to optimize this code

Hello all.

i first want to thank everyone for helping me in previous posts. i appreciate you guys.

now onto my issue.


honestly, i dont want to type every type of velocity or allignment out there. is there any class that applies to all of them?

so instead of

if velocity:IsA("LinearVelocity") or velocity:IsA("AllignPosition")...ect.

i could just do

if velocity:IsA("Something") then

if anyone can help that’d be great.

2 Likes

Try checking if the velocity is a constraint type.

If velocity:IsA(“Constraint”) then
–Do something
end

Hope this helps! :grin:

it would destroy welds then
and uh
everything that keeps the character together

or a i super duper wrong and it would be fine

If what @Kittylitterking123 said doesnt work, which it should but try this

local constraintTypes = {
    LinearVelocity = true,
    AlignPosition = true,
    AlignOrientation = true
}


for Index, Velocity in pairs(Humanoid.Parent:GetDescendants()) do

    if constraintTypes[Velocity.ClassName] then
        
    end
end
1 Like

i donot think that there are ways to make it more optimized

and its a simple if statment i donot think that it would be an intensive task

i will test this soon max charrr

“honestly, i dont want to type every type of velocity or allignment out there.”
Pretty hard to optimize one line. Possibly you could simplify the whole technique used.
Aimed at less total input needed. How well it works for you would depend on the ammout.

local velocityClasses = {
    "LinearVelocity", "AngularVelocity", "AlignPosition", "AlignOrientation",
    -- Any other classes needed
}

local function isVelocityClass(object)
    for _, className in ipairs(velocityClasses) do
        if object:IsA(className) then
            return true
        end
    end
    return false
end

-- calling class once
if isVelocityClass(velocity) then
    -- code for this class
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.