Can only tween objects in the workspace

I am finding a script on the dev form that I am modifying to make a notification popup, the problem is that I am touletmep of error messages that I do not know how to patch, that does not pose a problem except l when the event is spam or the system breaks

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CLIENT_Notification = ReplicatedStorage:WaitForChild("MSClient"):WaitForChild("Client_MSNotification")
 
local UI = script.Parent
local MaxNotifications = 4
local NotificationDuration = 4


function createNotification(TheTile,NotificationText)
	local Notifications = UI.Notif:GetChildren()
	script.NotificationPush:Play()
	if #Notifications >= MaxNotifications then
		Notifications[1]:TweenPosition(UDim2.new(1.5, 0, Notifications[1].Position.Y.Scale, 0),"InOut","Linear",0.2,true);wait(0.2)
		Notifications[1]:Destroy()
		for i,v in pairs(Notifications) do
			if v ~= nil then
				--pcall(function()
					v:TweenPosition(UDim2.new(0.97, 0, v.Position.Y.Scale - 0.12, 0),"InOut","Linear",0.2,true)
				--end)
			end
		end
		local NewNotification = UI.NotificationTemp:Clone()
		NewNotification.Name = tostring(#Notifications+1)
		NewNotification.Parent = UI.Notif
		NewNotification.Text.Text = NotificationText
		NewNotification:TweenPosition(UDim2.new(0.97, 0, 0.85, 0),"InOut","Linear",0.2,true)
		
	else
		for i,v in pairs(Notifications) do
			v:TweenPosition(UDim2.new(0.97, 0, v.Position.Y.Scale - 0.12, 0),"InOut","Linear",0.2,true)
		end
		local NewNotification = UI.NotificationTemp:Clone()
		NewNotification.Name = tostring(#Notifications+1)
		NewNotification.Parent = UI.Notif
		NewNotification.Text.Text = NotificationText
		NewNotification:TweenPosition(UDim2.new(0.97, 0, 0.85, 0),"InOut","Linear",0.2,true)
		delay(NotificationDuration,function()
			if NewNotification ~= nil then
				--pcall(function()
					NewNotification:TweenPosition(UDim2.new(1.5, 0, NewNotification.Position.Y.Scale, 0),"InOut","Linear",0.2,true);wait(0.2)
					NewNotification:Destroy()
				--end)
			end
		end)
	end
end
-- Function Activator
CLIENT_Notification.OnClientEvent:Connect(createNotification)

Try adding a debounce and see what happens.

i haven’t tried tween service in forever. Try using this plugin. Super helpful for tween service!

1 Like

What line is that error coming from?

It seems like you’re attempting to tween a GUI Instance that is parented to nil, or just removing an Instance that is in the middle of a tween. The tween API requires the target instance to be parented to the DataModel.

This code seems to be the culprit:

NewNotification:TweenPosition(UDim2.new(1.5, 0, NewNotification.Position.Y.Scale, 0),"InOut","Linear",0.2,true);wait(0.2)
NewNotification:Destroy()

I would suggest using game.Debris:AddItem(NewNotification, 1) rather than wait(0.2); NewNotification:Destroy(). Giving the tween plenty of time (in my example, an extra 0.8 seconds) to completely finish may solve your issue.

1 Like