Error while trying to use TweenPosition

I have written a script to tween a notification (maybe or maybe not a leak to my wip module), except when I run it I get this error: Players.dude8074alt.PlayerGui.NotificationGui.MainNotifs.1.MainSection.Tweening:2: attempt to index nil with 'Parent'

Here is the script:

while true do
	repeat wait() until script.Parent.Parent.Visible == true
	script.Parent:TweenPosition(
		UDim2.new(0,0,0,0),           -- Final position the tween should reach
		Enum.EasingDirection.In, -- Direction of the easing
		Enum.EasingStyle.Sine,   -- Kind of easing to apply
		0.25,                       -- Duration of the tween in seconds
		true                    -- Whether in-progress tweens are interrupted
	)
	wait(7)
	script.Parent:TweenPosition(
		UDim2.new(0,0,1.5,0),           -- Final position the tween should reach
		Enum.EasingDirection.In, -- Direction of the easing
		Enum.EasingStyle.Sine,   -- Kind of easing to apply
		0.5,                       -- Duration of the tween in seconds
		true                    -- Whether in-progress tweens are interrupted
	)
	script.Parent.Parent:Destroy()
end

And here is what it looks like in the explorer:
Screen Shot 2021-03-25 at 5.44.49 PM

Hello, how are you doing?

You can replace the Destroy line with script.Parent.Parent.Visible = false if you want it to keep repeating.
Also, before the while loop you should probably do:

repeat wait() until script.Parent.Parent ~= nil

If you want it to wait between each time it loops, you can change “true” with “wait(2)” or any other you’d like

I think you meant one equals sign, lol

My bad, accidentally wrote two instead of one.

I thought the problem was me destroying the object before it finished tweening, but that doesn’t seem to be it.

Can you send a screenshot of the console?

I don’t get any errors, it’s strange.

Can you send a screenshot of the directory?
Like a screenshot that shows the parent of the script, the parent of the parent of the script, until it reaches the StarterGui?

At the first line, write this:

print(script.Parent.Parent.Name)

Then run the script and send another screenshot of the console, i may have an idea.

Is the MainNotifs frame’s visible set to true or false? if it’s false then that’s the reason you aren’t able to see the 1 frame.

The frame is visible, but the problem is TweenPosition won’t tween it out.

Are you sure you’re setting everything right, and putting it on Scale when you’re going to tween?

Could you clarify what you mean by that?

Just found the solution, you’re forgetting to play the tween.

Change this:

Into this:

script.Parent:TweenPosition(
	UDim2.new(0,0,0,0),           -- Final position the tween should reach
	Enum.EasingDirection.In, -- Direction of the easing
	Enum.EasingStyle.Sine,   -- Kind of easing to apply
	0.25,                       -- Duration of the tween in seconds
	true                    -- Whether in-progress tweens are interrupted
):Play()
wait(7)
script.Parent:TweenPosition(
	UDim2.new(0,0,1.5,0),           -- Final position the tween should reach
	Enum.EasingDirection.In, -- Direction of the easing
	Enum.EasingStyle.Sine,   -- Kind of easing to apply
	0.5,                       -- Duration of the tween in seconds
	true                    -- Whether in-progress tweens are interrupted
):Play()

replace this with

wait(0.5)
script.Parent.Parent.Visible = false
wait(7) -- same as your last wait
script.Parent.Parent.Visible = true

The problem is you destroy right after TweenPosition which is a subroutine. Even though it’s a 0.5 second tween, it will “run it in the background” and the thread will continue. It doesn’t even get to tween before you destroy the parent. Plus you destroy it and you can’t use it again as it’s gone as well as the script itself since the script is a descendant of destroyed parent.

He changed his code, it’s not the same as before.
He probably forgot to edit it to the new one or put the updated one here.

I see. Editing that line removes the error and continues the loop infinitely.

This is incorrect, tween position should not be confused with Tween Service, TweenPosition work when called
Here is API Reference
TweenPosition