Script wont change parts size in loop

Hi, i created a script that rises a part, and whenever it reaches a certain amount of size, it makes the part the original size again and stops the growing. but it doesnt grow at all at the start.
i get this error:

here is my code:

while true do
					wait(0.01)

					Grow.Size = Grow.Size + Vector3.new(0.03,0,0)

					Grow.Position = Grow.Position + Vector3.new(0,0.015,0)
					
					if Grow.Size >= Vector3.new(82.476, 156.945, 135.364) then
						Grow.Size = Vector3.new(7.028, 156.945, 135.364)
						break
					end
				end
2 Likes

You can’t compare vector3s with those signs for engine reasons. Since you’re only changing the X, you can just compare the Size.X with 82.476 instead

1 Like

so something like this

				if Grow.Size.X >= (82.476) then
						Grow.Size.X = (7.028)
						break
					end
				end

1 Like

Set the size the way you were doing it before, that was right

2 Likes

With that it says 16:24:17.933 X cannot be assigned to - Server - Script:43

1 Like

Hi there, when the target size is reached this script should reset the size to the original size and break it out of the loop

local Grow = script.Parent  -- Assuming the script is a child of the "Grow" part
local originalSize = Vector3.new(7.028, 156.945, 135.364)
local targetSize = Vector3.new(82.476, 156.945, 135.364)
local growthRate = Vector3.new(0.03, 0, 0)
local positionChange = Vector3.new(0, 0.015, 0)

while true do
    wait(0.01)

    local currentSize = Grow.Size
    local newSize = currentSize + growthRate
    local newPosition = Grow.Position + positionChange

    if currentSize.magnitude < targetSize.magnitude then
        if newSize.magnitude > targetSize.magnitude then
            newSize = targetSize
        end
        Grow.Size = newSize
        Grow.Position = newPosition
    else
        Grow.Size = originalSize
        break
    end
end


2 Likes

Yes, I meant for you to change line 43 from “Grow.Size.X = (7.028)” to “Grow.Size = Vector3.new(7.028, 156.945, 135.364)”. That “X” property is read only so you can’t make a new size like that

1 Like

i have a question, do you know where i put in your script to also when the size resets to the original to change the position to 718.122, -13.29, 95.35?

1 Like

The script will work when its inside the Grow part and I added the line Grow.Position = Vector3.new(718.122, -13.29, 95.35) after resetting the size. This will set the position of the “Grow” part to the specified coordinates when the size resets to the original.

local Grow = script.Parent  -- Assuming the script is a child of the "Grow" part
local originalSize = Vector3.new(7.028, 156.945, 135.364)
local targetSize = Vector3.new(82.476, 156.945, 135.364)
local growthRate = Vector3.new(0.03, 0, 0)
local positionChange = Vector3.new(0, 0.015, 0)

while true do
    wait(0.01)

    local currentSize = Grow.Size
    local newSize = currentSize + growthRate
    local newPosition = Grow.Position + positionChange

    if currentSize.magnitude < targetSize.magnitude then
        if newSize.magnitude > targetSize.magnitude then
            newSize = targetSize
        end
        Grow.Size = newSize
        Grow.Position = newPosition
    else
        Grow.Size = originalSize
        Grow.Position = Vector3.new(718.122, -13.29, 95.35)  -- Reset the position
        break
    end
end

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.