How to make my function work

Hello, I have a script that notifies a player when something happens and I want it so that when the function is fired and it is in progress notifying something else it stops that and notifies the new notification
When there is a new notification it still disappears and does not stay to show that other notification
I haven’t found any solutions or thought of any solution.
This is my current script:

function notify(msg, remove)
	plr.PlayerGui.V1MainUi.Notification.Visible = true
	for i = 1, #msg do
		plr.PlayerGui.V1MainUi.Notification.Message.Text = string.sub(msg, 1, i)
		wait(0.05)
	end
	if remove then
		wait(2)
		for i=1,10 do
			plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency = plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency+0.1
			plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency = plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency+0.1
			plr.PlayerGui.V1MainUi.Notification.Message.Position = plr.PlayerGui.V1MainUi.Notification.Message.Position-UDim2.new(0,0,0,1)
			plr.PlayerGui.V1MainUi.Notification.Shadow.Position = plr.PlayerGui.V1MainUi.Notification.Shadow.Position-UDim2.new(0,0,0,1)
			plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency = plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency+0.1
			wait()
		end
		plr.PlayerGui.V1MainUi.Notification.Visible = false
		plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Shadow.Position = UDim2.new(0.5, 0,0.956, 0)
		plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Message.Position = UDim2.new(0, 0,0, 0)
	end
end

I’m not gonna look throught the whole script and tell you exactly the changes you have to do cause I’m lazy, but could you show a Video of how it functions so far so I can understand better?

My PC is bad it will freeze the entire part when I play it, basically, it works fine after you wait for it to disappear and finish typewriting the text but if you call the function during that process it will just typewrite both of the text (kind of) and it will disappear and weird stuff like that

Try this

local Stop = false

function notify(msg, remove)
	Stop = true

	plr.PlayerGui.V1MainUi.Notification.Visible = true
	Stop = false

	for i = 1, #msg do
		plr.PlayerGui.V1MainUi.Notification.Message.Text = string.sub(msg, 1, i)
		if Stop then break end
		wait(0.05)
	end
	if remove then
		wait(2)
		for i=1,10 do
			plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency = plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency+0.1
			plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency = plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency+0.1
			plr.PlayerGui.V1MainUi.Notification.Message.Position = plr.PlayerGui.V1MainUi.Notification.Message.Position-UDim2.new(0,0,0,1)
			plr.PlayerGui.V1MainUi.Notification.Shadow.Position = plr.PlayerGui.V1MainUi.Notification.Shadow.Position-UDim2.new(0,0,0,1)
			plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency = plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency+0.1
			wait()
		end
		plr.PlayerGui.V1MainUi.Notification.Visible = false
		plr.PlayerGui.V1MainUi.Notification.BackgroundTransparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Shadow.Transparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Shadow.Position = UDim2.new(0.5, 0,0.956, 0)
		plr.PlayerGui.V1MainUi.Notification.Message.TextTransparency = 0.2
		plr.PlayerGui.V1MainUi.Notification.Message.Position = UDim2.new(0, 0,0, 0)
	end
end

Thanks, it works perfectly fine!

1 Like