Changing text of UI through local script not saving after respawning

I have an UI that changes its text to a player’s name whenever they equip a specific object. Everything works fine and changes correctly. The only issue is that when a player resets, the text reverts back to the original and doesn’t keep the text it had before like it is supposed to. I made a server script that detects when a player has respawned and fires an event to the local script, which in theory should immediately update the gui to the new name, but instead it does not. Why?

(Just realized this is very confusing to read so I’ll link a detailed reply of what I mean)

do you have this checked OFF
image

also if this isnt what youre asking, please elaborate because i just spent 2 minutes trying to figure out the question

1 Like

Apologies, what I mean is when I set text of an UI through client script, it never stays when I respawn and I don’t know why. Here is a video

server script:

local RS = game:GetService("ReplicatedStorage")
local text = RS.Text

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		text:FireClient(player)
	end)
end)

Localscript:

local RS = game:GetService("ReplicatedStorage")
local text = RS.Text

text.OnClientEvent:Connect(function()
	script.Parent.Text = "hi"
end)

Okay think about it like this. When your character dies, EVERYTHING in the player is deleted.

When they respawn, they get a NEW clone of all your GUIS in StarterGui

So nothing actually is persistent

Oh shoot I didn’t see the last part my bad

1 Like

Wait I know why.

You’re firing the RemoteEvent within the scope of the PlayerAdded event and that only fires when the player joins (gets added)

instead of going through this whole server script fiasco, i’d reduce this whole system to the local script

local RS = game:GetService("ReplicatedStorage")
local text = RS.Text
local player = game.Players.LocalPlayer

player.CharacterAdded:Connect(function()
script.Parent.Text = "hi"
end)

also beware i wrote this all inside the devforum, so there might be a couple typos

1 Like

Server Script:

Try this code an let me know if it works big dog!! When the player joins the game, the server fires the event to the client, updating the text on the UI. Additionally, when the player’s character respawns, the event is fired again, ensuring that the text stays updated.

local textEvent = Instance.new("RemoteEvent", RS)
textEvent.Name = "TextEvent"

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        -- Fire the event to update the text when the character is added
        textEvent:FireClient(player, "hi")
    end)
end)

Local Script:



local RS = game:GetService("ReplicatedStorage")
local textEvent = RS:WaitForChild("TextEvent")

textEvent.OnClientEvent:Connect(function(text)
    script.Parent.Text = text
end)
1 Like

That would actually be better than firing a remote event. Been doing this for 3 years and I couldn’t even spot this mistake :man_facepalming:

Oh I assumed characteradded didn’t work inside a local script because it didn’t work the various other tests I ran. I’ll see if it works this time.

1 Like

Oh it does cuz the client has access to the character therefore it can see when the character spawns

But the script I wrote is ineffective and you shouldn’t use it

I just checked with the characteradded and it doesn’t seem to work. Could it be that it just doesn’t work on localscripts?

I used CharacterAdded a lot in LocalScripts, weird that it doesn’t work in your case

btw if your LocalScript is in StarterGui, you’re gonna need to have ResetOnSpawn enabled or CharacterAdded is only gonna fire once

Just turn off Reset on spawn in your screen GUI like this


Screenshot 2024-06-04 at 7.40.48 PM

Bro… it worked… I spent 3 days malding over this only to find out it could be solved in a single option :sob::sob::sob::sob:

2 Likes

wait what about this post lol

(The post I’m replying to)

Oh I must’ve missed that, my bad I was writting my corrected topic instead of looking.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.