local gui= game.StarterGui.plrdiedgui.Frame game:GetService('Players').PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() wait(0.3) local Textlabel = Instance.new("TextLabel") Textlabel.Parent = gui Textlabel.Position = UDim2.new(0.5, -100,0.5, -125) Textlabel.Size = UDim2.new(0, 200,0, 50) Textlabel.BackgroundColor3 = BrickColor.White().Color Textlabel.BackgroundTransparency = 1 Textlabel.Text = plr.Name .. tostring(" just died!") wait(5) Textlabel:remove() end) end)
This script fails to display this GUI to me until I've respawned, and when the Textlabel is removed, I still see the TextLabel. How do I overcome this?
This is one of the most common problems I see in peoples' code.
The Problem? You're attempting to change things in StarterGui. StarterGui is a bin. Everytime a player respawns, everything inside StarterGui is copied over into the player's PlayerGui. You can find out how to change things in PlayerGui here.
If you would like to change something in all players' GUIs, you can run a script like this:
for _, plr in pairs(game.Players:GetChildren()) do plr.PlayerGui.ScreenGui.Frame.Visible = true end
This iterates through all players in Game -> Players and changes the Visible property of a Frame to true in every players' PlayerGui folder.
Feel free to ask any questions in the comment section, I hope this helped!
A few notes:
You don't need to convert " just died!" to a string as it already is one, plr.Name .. " just died!"
will work absolutely fine.
You should never use :remove() in your scripts, it's deprecated and doesn't completely remove objects. Use :Destroy() instead.