This script is supposed to be invisible at first, but every time someone dies, it's supposed to be visible. The first time you die, it works, but if you keep dying it won't work. Can someone help me figure out why it doesn't work every time you die? Thanks.
G = script.NotificationGui F = G.Main T = F.PText S = script.Sound function appear() local P = game.Players:GetPlayers() for i=1, #P do local newg = script.NotificationGui newg.Parent = P[i].PlayerGui end end function disappear() local P = game.Players:GetPlayers() for i=1, #P do local newg = script.NotificationGui newg.Parent = P[i].workspace end end function Died(player) F.Visible = true print("Player Died") T.Text = (player.Name.." died.") appear() wait(5) F.Visible = false disappear() end game.Players.ChildAdded:connect(function(newPlayer) newPlayer.CharacterAdded:connect(function(Character) wait(0.01) Character.Humanoid.Died:connect(function() Died(Character) end) Died() end) end)
One issue I noticed is in your appear function.
function appear() local P = game.Players:GetPlayers() for i=1, #P do local newg = script.NotificationGui newg.Parent = P[i].PlayerGui end end
You are setting your variable 'newg' to your only copy of the Notification Gui. You should be cloning it.
function appear() local P = game.Players:GetPlayers() for i=1, #P do local newg = script.NotificationGui:Clone() --Clones Gui newg.Parent = P[i].PlayerGui end end
There is an issue with your disappear function as well.
function disappear() local P = game.Players:GetPlayers() for i=1, #P do local newg = script.NotificationGui newg.Parent = P[i].workspace end end
The goal of this function from interpretation is to go through the Player's PlayerGui and get rid of it. Instead you are trying to take your only reference of the Gui and put it inside a workspace directory located inside of the player, which doesn't exist. What you should be doing is trying to find the cloned Gui in the player's PlayerGui and destroying it.
function disappear() local P = game.Players:GetPlayers() for i=1, #P do local newg = P[i].PlayerGui:FindFirstChild("GuiName") --Replace GuiName with its name. if newg then newg:Destroy() end end end
Replace GuiName with the actual name of the cloned Gui object. The cloned object will have the same name as the original Gui.