Thank you for reading my question and considering helping me. To begin with I will tell you what I have been doing and what the objective is, I am using a loop to make a part grow until it reaches a maximum pre-established size and then start to decrease until it reaches a minimum pre-established size. This part of the code is working just fine.
The problematic part is stopping the loop, to do that I made a variable that needs to be true for the loop to run, so I did a touched function so that when I touched the part this variable becomes false and then the part would theoretically stop growing / decreasing, and in fact it kinda works, but the touched function waits for the loop to end for this to happen, that is, it waits until the part returns to the smallest possible size and only then stop the loop, which is not what I wanted, I want the part to stop the loop immediately when it is touched, staying at the size it was at the time of contact. What I have so far is this:
local Players = game:GetService("Players")
local GrowingPart = script.Parent
local grow = true
local MaximumSize = Vector3.new(8, 12, 8)
local MinimumSize = Vector3.new(8, 1, 8)
GrowingPart.Touched:Connect(function(Hit)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
grow = false
end
end)
while grow do
repeat
GrowingPart.Size = GrowingPart.Size + Vector3.new(0, 1, 0)
GrowingPart.Position = GrowingPart.Position + Vector3.new(0, 1 / 2, 0)
wait(1)
until GrowingPart.Size == MaximumSize
repeat
GrowingPart.Size = GrowingPart.Size - Vector3.new(0, 1, 0)
GrowingPart.Position = GrowingPart.Position - Vector3.new(0, 1 / 2, 0)
wait(1)
until GrowingPart.Size == MinimumSize
end
