Help with GUI Fix

I made a GUI, specifically a Notification System, with a typewriter effect. However, for some reason, when the character respawns [ LoadCharacter()/Die and Respawn ] if the GUI is currently performing the typewriter effect or is simply visible, it stops typing and just remains on the screen. It glitches and stays there indefinitely. Can someone help me fix this?

I think you can turn ResetOnSpawn off to fix this

It’s obviously alerady turned off.

otherwise it woudnt even have the typewrite bug

Do you have a code sample we can look at? It’s difficult to diagnose a problem here without one

It’s because the code doesn’t interfeer with anything. the notification just breaks because playergui is resetted on loadcharacter, so im trying to find a workround

Where is the script located? Code execution only halts like that if it’s destroyed

its a module in the replicatedstorage

We ask for your exact code because this shouldn’t be happening.

for some reason the playergui.parent refreshes whenever the character loads.

What script is calling the module script functions?

A localscript in starterplayerscripts

i’ll give the typewrite logic.

for i = 1, #fullText do
		if (getStateForPlayer(player).CancelToken or 0) ~= myToken then
			if currentTween then pcall(function() currentTween:Cancel() end) end
			if toast and isDescendantOfPlayerGui(player, toast) then
				pcall(function() animateOut(toast) end)
			end
			return
		end

		if not isDescendantOfPlayerGui(player, toast) then
			if currentTween then pcall(function() currentTween:Cancel() end) end
			pcall(function() animateOut(toast) end)
			return
		end


		local sub = string.sub(fullText, 1, i)
		label.Text = sub

		local measuredRendered = robustMeasureRenderedText(label, sub)
		local desiredAbsWidth = math.ceil(measuredRendered + PADDING_FOR_TITLE * 2)
		local desiredOffset = math.max(1, math.ceil(desiredAbsWidth / uiscaleFactor))


		local heightOffset = s.Config.Height or DEFAULTS.Height


		local targetSize = UDim2.fromOffset(desiredOffset, heightOffset)

		if currentTween then
			pcall(function() currentTween:Cancel() end)
			currentTween = nil
		end

		local tweenTime = math.clamp(sspd * 0.5 + 0.04, 0.02, 0.25)
		local ok, t = pcall(function()
			return TweenService:Create(toast, TweenInfo.new(tweenTime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), { Size = targetSize })
		end)
		if ok and t then
			currentTween = t
			pcall(function() t:Play() end)
		end

		task.wait(sspd)
	end

Why so many pcall()s? The tween functions don’t error if you use them properly. It’s possible that one of them is catching an error that would tell you what the issue is but it’s being caught and ignored.

Also, if it’s not too much work, can you provide a place file with the minimum code required to reproduce the behavior you’re seeing? It’ll help us fully contextualize what your code is interacting with and just might reveal the bug to you.

Otherwise, I’d wait for someone more perceptive to analyze your code. I don’t see anything obviously wrong, but I would caution against both pcalls and the way you’re calculating a new size for the label. What’s wrong with AutomaticSize and TextLabel.MaxVisibleGraphemes?

for i = 1, #fullText do
    local gui = player:FindFirstChild("PlayerGui")
    local toast = gui and gui:FindFirstChild("ToastFrame")
    local label = toast and toast:FindFirstChild("Label")
    if not toast or not label then
        if currentTween then pcall(function() currentTween:Cancel() end) end
        return
    end

    if (getStateForPlayer(player).CancelToken or 0) ~= myToken then

Oh, why am i calculating the size? It’s because every 1 new letter the GUI gets bigger.

These are your two conditions for the typewrite loop terminating, so either your token check is failing or there’s a flaw in your logic for checking if the gui is a descendant of the player gui.

It would help to see how the getStateForPlayer() and isDescendantOfPlayerGui() functions look

Right, but what’s wrong with using AutomaticSize.X(Y)?

Also, try without the pcalls, just programming defensively (if a tween errors, use an if to only run when it won’t) like

if toast then
    -- tween
end

assuming you got an error there that toast didn’t exist.

Is isDescendantOfPlayerGui just

local function isDescendantOfPlayerGui(player, object)
    local gui = object:FindFirstAncestorOfClass("PlayerGui")
    return (gui and gui.Parent == player)
end

All I can say is that removing all those pcalls and adding prints/breakpoints around your conditionals when you try to cancel the loop or the tweens might point to the error.

I still recommend trying to reproduce this on a new place file with as little code as possible. It’ll probably help you and us to spot the error.