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

If statement to Vector3?

Asked by 9 years ago

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?

0
have you used the `for` loop? woodengop 1134 — 9y

1 answer

Log in to vote
2
Answered by
davness 376 Moderation Voter
9 years ago

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
1
.01 and 0.010000000 are both the same decimals since the both them in Hundredths decimal place. UserOnly20Characters 890 — 9y
1
thanks it helped!! robloxishot123123 0 — 9y
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. Goulstem 8144 — 9y
Ad

Answer this question