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)
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)
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
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)