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

If statement to Vector3?

I tried creating something that shrinks, it shrinks but i want to break the loop when the mesh scale is at 0,0,0 this is my script;

while true do
	script.Parent.Part.Mesh.Scale = script.Parent.Part.Mesh.Scale - Vector3.new(.01, .01, .01)
	wait(.1)
	if script.Parent.Part.Mesh.Scale == Vector3.new(0, 0, 0) then
		break
	end
end

obviously the error is

if script.Parent.Part.Mesh.Scale == Vector3.new(0, 0, 0) then

pretty much my question is how do i make an if statement to vector3?

1 comment

0

have you used the for loop?

1 answer

Your IF statement is correct, but, unfortunately, when you're lowering the scale, it won't low .01 a time, it would low 0.0100000(something). So it will NEVER reach zero.

So where you have

if script.Parent.Part.Mesh.Scale == Vector3.new(0, 0, 0) then

You should have

if script.Parent.Part.Mesh.Scale <= Vector3.new(0, 0, 0) then

So, it will break the script when the scale is equal or lower than ZERO.

But it would leave a little mesh. So, after the loop. it's time to set the scale to zero.

script.Parent.Part.Mesh.Scale = Vector3.new(0, 0, 0)

Rewritten script

while true do
    script.Parent.Part.Mesh.Scale = script.Parent.Part.Mesh.Scale - Vector3.new(.01, .01, .01)
    wait(.1)
    if script.Parent.Part.Mesh.Scale <= Vector3.new(0, 0, 0) then
        break
    end
end
script.Parent.Part.Mesh.Scale = Vector3.new(0,0,0)

But this script doesn't work. I had made changes to it

while  script.Parent.Part.Mesh.Scale.X > 0 and script.Parent.Part.Mesh.Scale.Y > 0 and script.Parent.Part.Mesh.Scale.Z > 0 do
    script.Parent.Part.Mesh.Scale = script.Parent.Part.Mesh.Scale - Vector3.new(.003,.003,.003) --increase or reduce it like you want
    wait() -- fluid shrinking
end
script.Parent.Part.Mesh.Scale = Vector3.new(0,0,0) -- it will force the total shrinking of the part

3 comments

1

.01 and 0.010000000 are both the same decimals since the both them in Hundredths decimal place.

1

thanks it helped!!

2

What he's trying to say is that you'e creating a float value by subtracting Vectors. Therefore the value you're checking to be equivilant to 0 isn't ever going to be exactly 0.. it'll be like .001 or -.0000001. And even the smallest margin of error makes it so your conditional does not return true.

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