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

How do I make a GUI appear when they die?

Asked by 9 years ago

So I want the GI to appear when they die; but I fear that when they do, after a few seconds the gui will go away. Unless there is a way to disable the ability to respawn.

wait(1)
text = game.StarterGui.DeathGUI.Frame.NumberCount
gui = game.StarterGui.DeathGUI.Frame

local b = game.Workspace.Player:FindFirstChild("Humanoid")
if b ~= nil then
    if b.Health == 0 then
        wait(5)
    gui.Visible = true
    end
end


character:Humanoid.Died:connect(function() 
    local b = game.Workspace.Player:FindFirstChild("Humanoid")
    if b ~= nil then
    if b.Health == 0 then
    wait(5)
    gui.Visible = true
        end
    end
end)

(Note: I feel like I posted a question about this a while back, but I cannot find it. Sorry if it is spam.)

1 answer

Log in to vote
0
Answered by 9 years ago

Well, i'm not very good with GUI. So your GUI looks fine and all, but there are a few things that need fixing. I'll try not to touch most of your variables and functions, sorry if I do. Here are the following problems with your script: 1) You cant index the player using game.Workspace.Player because player is not a valid member of the workspace
1a) To fix problem 1 you'd replace it with the following code game.Players.LocalPlayer. Now this should only work if you place the script in the StarterGui service.
2) With line 14 you cant include two functions/connection lines within that function.
2a) To fix this, you'd have to create a variable at the begging of the script that specifies the player (It would look like this: player = game.Players.LocalPlayer

So now that we have indentified all the problems, let's see what the script would look like:

wait(1)
text = game.StarterGui.DeathGUI.Frame.NumberCount
gui = game.StarterGui.DeathGUI.Frame
player = game.Players.LocalPlayer       --We'll create a variable that specifies the client (the player that is running the GUI)

local b = player:FindFirstChild("Humanoid")
if b ~= nil then
    if b.Health == 0 then
        wait(5)
    gui.Visible = true
    end
end

player.Died:connect(function()      --now that we've indexed the player, the event were using is a member of that player
    local b = player:FindFirstChild("Humanoid")
    if b ~= nil then
    if b.Health == 0 then
    wait(5)
    gui.Visible = true
        end
    end
end)

Of coarse there may be other stuff that isnt working. I only give the errors that are obvisous and need fixing. If you need a deeper explanation, I have a bunch of links below. If you need help, please comment.

The Players Service: http://wiki.roblox.com/index.php?title=API:Class/Players Player Description: http://wiki.roblox.com/index.php?title=API:Class/Player An in-depth scripting guide: http://wiki.roblox.com/index.php?title=Scripting_Book

0
Mk. I also have this problem 22:12:03.455 - Died is not a valid member of Player 22:12:03.461 - Script 'Players.Player.PlayerGui.DeathGUI.Frame.NumberCount.Script', Line 14 22:12:03.463 - Stack End DeveloperSolo 370 — 9y
0
Wooops I almost forgot. There is no died event for a certain player. You'd instead replace it with the following code: player.Character.Humanoid.Died:connect(function() LateralLace 297 — 9y
0
Ok. thanks, now I just need to figure out a way to make it actually appear. By any chance you know how? DeveloperSolo 370 — 9y
0
I'd be happy to change up the script a little to make it work! LateralLace 297 — 9y
0
Sure! DeveloperSolo 370 — 9y
Ad

Answer this question