Block Properties script not working

Hi all!

I am currently running this in the command bar & it is not working, yet the way I have it programmed, should have it to work. The MeshPart(s) it should be working on is a (MeshPart,Transparency 0.8, Material Concrete).

Can Anyone help please, thanks!

for _,v in pairs(game.Workspace:GetDescendants()) do
    if v:IsA("MeshPart") and v.Transparency == 0.8 then v.Material = Enum.Material.SmoothPlastic   v.BrickColor = BrickColor.new("Really black")   
end end

This is probably because of floating point inaccuracies. The actual transparency of the part might be something like 0.80000000123 which is not equal to 0.8

image

image

To fix this you could check if the transparency’s error is no more than like 0.00001 with math.abs, e.g. it would accept any part with transparency from 0.79999 to 0.80001

2 Likes

How could I implement this to my script?

for _,v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("MeshPart") then
		local err = math.abs(v.Transparency - 0.8)
		if err < 0.0000001 then
			v.Material = Enum.Material.SmoothPlastic
			v.BrickColor = BrickColor.new("Really black")
		end
	end
end

Can’t y’all just use math.floor?

for _,v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("MeshPart") and math.floor(v.Transparency) == 0.8 then
		v.Material = Enum.Material.SmoothPlastic  v.BrickColor = BrickColor.new("Really black")   
	end 
end

That doesn’t work either. If you would like to communicate on Discord with me, Mboy#4007.

@Jackscarlett pretty sure math.round rounds to the nearest whole number. @NeonTaco135 Same thing here.

This did it, Thank You very much!

(Nevermind I’m just being dumb)

@Mboy00 Make sure to mark that helped you the most as a solution :slightly_smiling_face:

The transparency is an actual number :​P It’s outputting zero because math.round rounds the number to the nearest whole number (no decimals)

math.round(0.4) -- > 0
math.round(0.4999) -- > 0
math.round(0.5) -- > 1
1 Like