Object deleted without running rest of script

Hey folks, I’m still new to scripting, and I’m trying to make a script that makes an object slowly disappear over time until it reaches transparency 1 at which point it gets parented to nil, but it seems to just delete the object without doing the rest of the script.
I’ve rewritten the script a couple times after doing some research on loops, and I’ve ended up with this:

Object = script.Parent
Transparency = Object.Transparency

while Transparency > 1 do repeat
		if Object.Parent.Name == "Katamari" then
			while Transparency > 1 do
				wait(1)
				Transparency = Transparency + 0.1
			end
		end
	until Transparency == 1
end
Object.Parent = nil

It looks as if it should work to me, but clearly I have some gaps in my knowledge since it doesn’t. Does anybody know what I am doing wrong?

You want while transparency is LESS than 1…

OR you want repeat until transparency equals 1.

You don’t want both… that’s going to create some shenanigans. Try this:

Object = script.Parent
Transparency = Object.Transparency

if Object.Parent.Name == "Katamari" then
   while Transparency < 1 do 
		wait(1)
		Transparency = Transparency + 0.1
   end
end
Object.Parent = nil
1 Like

you mean like this?

Object = script.Parent
Transparency = Object.Transparency

repeat
	wait(1)
	if Transparency <1 then
		Transparency += 0.1
	end
until
Transparency == 1

Object.Parent = nil

Thankyou, this solved half my issue since the object now disappears in 10 seconds as it should, but It still doesn’t change the transparency for some reason. I think It may have to do with my grammar on line 7, but I’m not sure what should be changed. Any ideas?

better calculate the time and the change

Object = script.Parent
Transparency = Object.Transparency

if Object.Parent.Name == "Katamari" then
	
	for i = 0.1, 1, 0.1 do
		wait(1)
		Object.Transparency = i	
	end
	
	Object.Parent = nil
end
1 Like

Ohhh! It works perfectly now, I’ve always had some trouble understanding loops like in line six, I think I’ll do some more research on that in the coming time. Thanks a bunch for your help, have a good week.