Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

1 comment

0

Thanks, it doesn't lag now.

This discussion is preserved as it was. New answers, comments, and votes are closed.