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
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
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?
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()
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.