The first thing I’d fix with your code is the formatting; please make sure to use indentation and spaces consistently - it makes your code easier to read for yourself and for others.
for transparency = 0, 1, 0.05 do
script.Parent.Frame.BackgroundTransparency = transparency
wait(0.01)
print("hi")
if script.Parent.Frame.BackgroundTransparency == hi then
script.Parent:Destroy()
end
end
Secondly, script.Parent.Frame.BackgroundTransparency == hi makes no sense in the context of the code you posted - there isn’t a variable called ‘hi’ anywhere in your code you posted. I’ll make an educated guess and assume that what you mean to do is delete script.Parent when you reach the end of the fade.
In that case, you can simply put it after the loop:
for transparency = 0, 1, 0.05 do
script.Parent.Frame.BackgroundTransparency = transparency
wait(0.01)
end
script.Parent:Destroy()
Next, if you want to fade starting from transparency 1 to transparency 0, you need to change your for loop to start at 1, finish at 0, and add -0.05 each step:
for transparency = 1, 0, -0.05 do
script.Parent.Frame.BackgroundTransparency = transparency
wait(0.01)
end
script.Parent:Destroy()
Finally, since wait() can’t wait for less than 1/30 of a second, you may as well remove the parameter you passed to it:
for transparency = 1, 0, -0.05 do
script.Parent.Frame.BackgroundTransparency = transparency
wait()
end
script.Parent:Destroy()
However, I’d recommend using @Intended_Pun’s method using TweenService (if you’re comfortable using it, of course). Hopefully this helps you understand how to fix it 