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

How would you decrease the size of a part using for i =1?

I was trying to do this, when someone touches it, it would decrease into zero and killing someone. Here's what I got

function onTouched(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if Humanoid then
		for i = 1, 20 do
			script.Parent.Size = Size.new - 1
			if script.Parent.Size == 0 then
				Humanoid.Health = -5
				print("Execution was successful!")
			end
		end
	end
end
script.Parent.Touched:connect(onTouched)

I need a good answer :c

2 comments

0

Do you want it to shrink in all directions? And it is impossible for a brick's size to be equal to 0.

0

I know, I also thought of that just right now. Yeah, I'd like it to decrease in all directions.

1 answer

Size is a Vector3 value. On top of that, it would be better to set the the size to i, since you already have a changing variable. Also make sure you have a wait().

for i = 20,1,-1 do --Counts down from 20
	script.Parent.Size = Vector3.new(i,i,i)
	wait(0.5)

You may also want to look into adding a debounce.

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