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