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

How do you change the size of a brick and if the brick touches...? (LOOK INSIDE TO UNDERSTAND)

i am trying to make a part that will infinitely change the x size of the part this is what i mean a brick that does a while loop to change the x size of the brick.

i have the script to change the size:

while true do
	script.Parent.Size = script.Parent.Size + vector3.new(1,0,0)
end

How would i stop changing the size of the part if the part touches another part or brick?.

2 comments

0

Check if the part is a humanoid or not

0

not a humanoid

2 answers

✓ Accepted answer

Well I would put the loop in another thread and use the Wait function of the event so that when the basepart touches another basepart it will change the value of a variable to something else.

Samples:

Running a while loop with code after to represent that while loops yield the current thread:

while true do
	wait(1)
end
print('wow potato')--never printed

Running the same while loop on a different thread:

spawn(function()
	while true do
		wait(1)
	end
end)
print('wow potato')--wow potato

Repeating adding a number until the basepart is touched using Wait

local part = part
local IsTouched = false

spawn(function()
	while not IsTouched do
		part.Size = part.Size + Vector3.new(1,1,1)
	end -- adding size in a different thread, will
	-- keep adding size until the variable IsTouched
	-- is true
end)

part.Touched:Wait()-- this function also can yield the
-- current thread, it will stop yielding once the event
-- is invoked
IsTouched = true

Using Connect to stop looping size (You do not need to add another thread):

local part = part
local IsTouched = false

part.Touched:Connect(function()
	IsTouched = true
end)

while not IsTouched do
	part.Size = part.Size + Vector3.new(1,1,1)
end

1 comment

0

than you @SoftlockedUnderZero

First of all, you forgot to add a wait, never a good thing in a loop. You also NEED to remember capitalization! Change your loop to this:

while true do
	script.Parent.Size = script.Parent.Size + Vector3.new(1,0,0)
	wait() --[[Change this to time in SECONDS. Leave it as wait() if you want the block to grow 1 stud in the 'X' direction EVERY 0.3 SECONDS. If you want it to grow every one second, change it to one.]]
end

Try it, and see if it works.

2 comments

0

Not sure how to stop it when it touches the brick. Maybe you could use a constraint or FindPartsInRegion3 to stop the block from growing if it detects a different block.

0

Thankyou @2Loos

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