GUI on client not updating

I have made a system that fires a string to the client to display a message on a screengui textlabel. I want the textlabel to update if the player characters resets / reloads or if a new player joins the game.

I haven’t tested the player joining the game part yet, but the issue I’m having is that even though the character resets and the client detects an event being fired, the GUI doesn’t change.

Also you don’t have to but if you see any issues with the detecting player joining part, it’d be nice if you pointed those out too.

local playerAddedConn = nil

local function sendMsg(msg: string)

	if playerAddedConn then
		playerAddedConn:Disconnect()
		playerAddedConn = nil
	end

	local function syncPlayer(player: Player)
		print("syncing msg")
		msgEvent:FireClient(player, msg)
	end
	
	msgEvent:FireAllClients(msg)
	
	workspace.ChildAdded:Connect(function(char:Model)
		if char:IsA("Model") then
			local plr = game.Players:GetPlayerFromCharacter(char)
			if plr then
				syncPlayer(plr)
			end
		end
	end)

	playerAddedConn = Players.PlayerAdded:Connect(function(player)
		task.spawn(function()
			syncPlayer(player)
		end)
	end)
end

Here is the receiving local script (I forgot to add it when posting initially, sorry!)

local event = game.ReplicatedStorage.MessageEvent
local Text = script.Parent

local currentIteration = 0

event.OnClientEvent:Connect(function(msg:string, skipAnim:boolean)
	print("recieved")
	currentIteration += 1
	
	skipAnim = skipAnim or false
	if skipAnim == false and msg then
		print("changing msg")
		local msgChars = {}

		for i = 1, #msg do
			table.insert(msgChars, msg:sub(i, i))
		end

		local oldMsg = ""
		local storedIteration = currentIteration

		for i,v in ipairs(msgChars) do
			if storedIteration == currentIteration then
				local newMsg = oldMsg.."|"
				Text.Text = newMsg

				task.wait(0.05)

				local newMsg = oldMsg..msgChars[i]
				Text.Text = newMsg

				oldMsg = newMsg
			else
				break
			end
		end
		print("message updated")
	else
		if msg then
			print("skipped anim")
			Text.Text = msg
		end
	end

end)

EDIT: I have made a new development. the timer is not updating because of a system I have made to apply a skin to the player character that unintentionally causes the event to fire multiple times in a short period . If anyone can find a solution now it’d be appreciated:

local function applySkin(plr:Player, skin:Model)
	if skin and skin:IsA("Model") then
		local newSkin = skin:Clone()
		newSkin:PivotTo(plr.Character.WorldPivot)
		newSkin.Name = plr.Name
		plr.Character = newSkin
		newSkin.Parent = workspace

	else
		warn("no skin passed")
	end
end

FYI, I took the skin applying system from a free model

First of all, you should move your connections (playerAddedConn and workspace.ChildAdded) out of the function or it will have a negative impact on server performance since its never disconnected.

I see PlayerAdded event being disconnected but it seems like you should just move the entire event out of the function.

local function syncPlayer() is also unnecessary because msgEvent:FireAllClients() already sends the same arguments to all players.

Don’t know if it is intended but Workspace.ChildAdded will run the first time the player loads in

local function sendMsg(msg: string)
	msgEvent:FireAllClients(msg)
end

Players.PlayerAdded:Connect(function(player) -- Send a message everytime a player joins
	sendMsg() -- task.spawn isn't needed
end)

workspace.ChildAdded:Connect(function(char: Model)
	if char:IsA("Model") then
		local plr = game.Players:GetPlayerFromCharacter(char)
		if plr then
			sendMsg()
		end
	end	
end)

I noticed it running when the player first joins, but I left it in since it doesn’t affect anything. do you know why the gui isnt updating on the client though?

I have found the solution. the way I was applying the skin by fully resetting the character interrupted the process on the client in some way. I am not 100% sure, but I have fixed the issue by manually going through the skin and cloning/replicating stuff over onto the player character