Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this GUI only work one time, and when you keep dying it won't show anymore?

Asked by 8 years ago

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)
0
You're placing it in the Player's PlayerGui but not the StarterGui so it will not show up again when they respawn. Putting it in the StarterGui will make it visible for all players though. FearMeIAmLag 1161 — 8y
0
ResetPlayerGuiOnSpawn defaults to false I believe, so FearMeIAmLag is incorrect. Whatever is placed in the PlayerGui stays there unless you change it. Sparker22 190 — 8y

1 answer

Log in to vote
0
Answered by
Sparker22 190
8 years ago

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.

0
Thank you, sir. PresidentAlvarez 5 — 8y
Ad

Answer this question