Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a less laggy way I could change the color of multiple blocks in range?

Asked by 5 years ago
Edited 5 years ago

So I'm trying to make a modified paint brush that has a size setting, and paints parts in range of the size when a part is pressed. Currently I'm using GetDescendants() and Magnitude to tell if a part is in range but it lags the game a bit. Wondering if there was any other way to do this without the lag? This is the part this concerns:

function setColor(part)
    local getDescendants = workspace:GetDescendants()
    if canSelectObject(part) and not db then
        db = true
        if brushType == "PaintBrush" then
        if inGui ~= true and inPalette ~= true then
        if eyeDropperImg2 ~= nil then eyeDropperImg2:Remove() end
        if script.Parent.area.Value == 1 then
            script.Parent.Color:FireServer(1,part,primaryColor.BackgroundColor)
        else
            script.Parent.Color:FireServer(1,part,primaryColor.BackgroundColor)
            for i,v in pairs (getDescendants) do
            if v.ClassName == "Part" and v.Locked == false or v.ClassName == "UnionOperation" and v.Locked == false then
            if v ~= part then
            if (part.Position - v.Position).magnitude < script.Parent.area.Value then
            if (v.BrickColor ~= primaryColor.BackgroundColor) then
                script.Parent.Color:FireServer(1, v, primaryColor.BackgroundColor)
            end
        end
        end
        end
        end
        end
        end

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

You can use the method that I describe here to achieve this:

https://scriptinghelpers.org/questions/60744/best-way-to-check-if-a-player-is-within-radius-of-something#59095

Region3s allow you to restrict the detection to only the parts surrounding the character. You can then check the magnitude of parts detected within the region to make it a spherical detection rather than a cube. I go into more detail on how it works in my other answer.

Hope this helps!

0
Thanks, it doesn't lag now. BetterNotDie 11 — 5y
Ad

Answer this question