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

How can I make a script stop only for a specific child?

Asked by 5 years ago

So my script currently works, except for the fact that even if the parts Y size is above 2.4, it will still gain value.

How can I make it so it will stop for that specific child?

while wait() do
    for index, child in pairs(game.Workspace.Lawn:GetChildren()) do
    if child.Size.Y ~= 2.4 then
    child.Size = child.Size + Vector3.new(0,0.2,0)
else
    child.Size = child.Size + Vector3.new(0,0,0)
end

child.CanCollide = true
child.Anchored = false
wait(0.05)
child.CanCollide = false
child.Anchored = true
end
    wait(10)
end

2 answers

Log in to vote
1
Answered by
dirk2999 103
5 years ago

To your above comment question,

Changing the size changes it from the center equally.

Not sure if that makes sense but I'll try to make more sense of it,

If you change a parts size by 1 on the Y axis, the size will increase by .5 on the top and .5 on the bottom. To correct this move the brick's CFrame up by half of what you increase the size

while wait() do
    for index, child in pairs(workspace.Lawn:GetChildren()) do
    if child.Size.Y >= 2.4 then
    child.Size = child.Size + Vector3.new(0,0.2,0)
    child.CFrame = child.CFrame + CFrame.new(0.0.1,0) --Bringing it up half of what the size increased
else
    child.Size = child.Size + Vector3.new(0,0,0)
end

child.CanCollide = true
child.Anchored = false
wait(0.05)
child.CanCollide = false
child.Anchored = true
end
    wait(10)
end
0
Line 5 would error, since you cannot add CFrame values. Change it to + Vector3.new(0, 0.1, 0) User#19524 175 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The thing about the ~= operator is that if the number is not equal to 2.4, code will run. The number can be greater or less than 2.4, as long as it's not equal to 2.4. To fix this, make your ~= to >.

if child.Size.Y > 2.4 then

The > means "greater than", the < means "less than", the == means "equal to", the ~= means "not equal to", the <= means "less than or equal to", and the >= means "greater than or equal to".

0
This probably isn't related to scripting, but how can I make it so when the size changes it doesn't sink through the floor? VeryDarkDev 47 — 5y
0
I don’t know. User#19524 175 — 5y

Answer this question