I am trying to make a bomb that makes a dent in the nearby dirts. But the dirt transparency part is not working as intended. What I am trying to do is make it destroy all dirts in the inner radius and make the rest be more transparent (the more the closer it is to bomb) here is my code:
for i, dirt in ipairs (workspace.Dirts:GetChildren()) do
local innerRadius = 40
local outerRadius = 50
local changeInX = innerRadius - outerRadius
local changeInY = 1 - 0
local multi = changeInY / changeInX
if (bomb.Position - dirt.Position).Magnitude <= outerRadius then
dirt.Transparency = dirt.Transparency + (bomb.Position - dirt.Position).Magnitude * multi
print(dirt.Transparency)
if dirt.Transparency >= 1 then
dirt:Destroy()
end
end
end
2 Likes
What does the function do, or does it not work at all? Additionally, BasePart.Transparency cannot be greater than 1 or less than 0 so that may be the issue.
1 Like
No its works and is getting called but for some reason my math is not right.
Here is a model with both the tool and the dirts to show what I am doing Test - Roblox
Are all bricks made transparent, or are none being made transparent? I will check out the model you posted if we can’t figure it out.
I noticed that the multiplier will always be a negative, was that intentional? If a transparency of 0 is the value then it will never increase because 0 is being added to by a negative. It is important to recognize magnitude will never be negative, so negatives do not cancel out to add to transparency.
1 Like
Yes ive tried with both negative and non negative multi 
All are being made all the way transparent and then deleted I want the parts in the inner radius to be transparent and then deleted but the ones in outer to only be partially transparent
Sorry it took me so long to get back to you. Is this the effect you are looking for?
If so, here is the edited code:
local innerRadius = 30
local outerRadius = 50
local changeInX = outerRadius - innerRadius
local changeInY = 1 - 0
local multi = changeInX / changeInY
if (bomb.Position - dirt.Position).Magnitude <= changeInX then
dirt:Destroy()
elseif (bomb.Position - dirt.Position).Magnitude <= changeInX + 30 then
dirt.Transparency = dirt.Transparency + multi / ((bomb.Position - dirt.Position).Magnitude)
if dirt.Transparency >= 1 then
dirt:Destroy()
end
end
end
I made a few tweaks as you can probably see. I can DM you the logic behind them if you would like, but if you are satisfied then I am too.
2 Likes
YES! exactly! what was your process of getting that?
First off, I added the first if statement to destroy any brick within 20 studs of the bomb because that was the intended effect.
Second, I just put in a lot of prints to check what was going on and I noticed that this print was giving large transparency values and large magnitude values in the undesired direction (further out blocks were being destroyed instead of close ones). I attributed this to a small multiplier so I flipped the multiplier (changeInX/ changeInY rather than vice versa) so that it’d be a larger number.
I divided into the multiplier because the magnitudes were very high and resulted in wonky results. This multiplier got them down to values I could comprehend better and from there I tweaked them until I got the desired effect.
Basically the process was just to take educated guesses and mess with values.
1 Like