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

How do I make a Gui transparent once a player dies?

Asked by 7 years ago
Edited 7 years ago

Hey,

I have a spectate Gui in my game, and I want to know how to make the spectate gui transparent (so visible = false) once a player dies (health = 0).

I have tried a multitude of scripts, but none of them seemed to properly worked.

Here is the script :

local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]

function onClick()
script.Parent.Visible = false
script.Parent.Parent.Close.Visible = true
script.Parent.Parent.Bar.Visible = true
script.Parent.Parent.Button.Visible = true
script.Parent.Parent.DescriptionFrame.Visible = true
script.Parent.Parent.ShopTitle.Visible = true
end

script.Parent.MouseButton1Down:connect(onClick)

while true do
    if game.Players.LocalPlayer.HealthDisplayDistance == 0
        then game.Players.LocalPlayer.PlayerGui.Spectate.Spectate.Open.Visible = false
    end
end

Someone please help me!

Thanks, Joy.**

0
try adding Workspace.StarterGUI.{GUI name} transparency something 1 after if game.players.localplayer.healthdisplaydistance ==0 thecoolx123 -5 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Well, you can detect when a humanoid dies with a .Died event

But wait, there is a problem.

.Died only works on the server

and we all know guis should be managed on the client

How do we fix that?

Remote events of course!

SETUP Inside of replicatedstorage, insert a remote event (name it anything you want)

Make a LOCAL SCRIPT that will manage the event, and put it in starter gui

Make a SERVER SCRIPT that will manage when the player dies (If you want to have it in another script, that's chill just ignore this)

Inside the local script, put the following

local plr = game.Players.LocalPlayer
local plrGui = plr.PlayerGui
local gui = plrGui.Spectate
local buttontomaketransparent = gui.Spectate.Open--path to it, if you already have a variable for it, then just use that
re = game.ReplicatedStorage.RemoteEvent -- or whatever you named it

re.OnClientEvent:connect(function(request) --When it is fired, do
    if request == "show" then --If the server wants to show it, do
        buttontomaketransparent.Visible = true
    elseif request == "hide" then --If the server wants to hide it, do
        buttontomaketransparent.Visible = false
    else
        return false
    end
end)

Inside the script where you want to manage the .Died event put this

re = game.ReplicatedStorage.RemoteEvent -- or whatever you named it

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function() --When the humanoid dies, do
            re:FireClient("hide")
        end)
    end)
end)

When you want to make the spectate button visible again then just do

re:FireClient("show")

Questions? Comments? Concerns? Make sure to comment and I'll be sure to get to it!

Did I make an error? Please peacefully tell me in the comments and I'll correct it. (it would probably be a silly mistake anyway)

Sources

Remote Events

Humanoid Died Event

Thanks,

John

0
Hi, thank you for your answer! It did not work however, it put me a red line on the local buttontomaketransparent = gui. part :/ JoyRUnderwood 5 — 7y
0
Did you put the path to the gui you want to make visible/invisible? DeveloperSolo 370 — 7y
0
I edited it so it would give the path of what you showed in your original script DeveloperSolo 370 — 7y
0
I just tested it (in a Local Server + 1 Player with FilteringEnabled): Died does work on the client. Usually the API tells you specifically if it only works on the server/client. chess123mate 5873 — 7y
0
I know Died event doesn't work on the client. Hence why I said '.Died only works on the server' DeveloperSolo 370 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

There is a much easier way to do this..

Lets use a script:

game.Players.PlayerAdded:Connect(function(p) 
    p.CharacterAdded:Connect(function(c) 
        print("Adding Player")
        c:WaitForChild('Humanoid').Died:Connect(function() 
            print("Adding Character")
            p.PlayerGui.Spectate.Spectate.Visible = false
        end) 
    end) 
end)

This is just the general concept, you will have to change the script to what your GUI is..

Log in to vote
0
Answered by 7 years ago

Thank you for your answer, but it still didn't work :/

1
Post comments to people you're referring to. There's no reason to post an answer to your own question unless it's an actual answer explaining how you yourself found a solution. OldPalHappy 1477 — 7y

Answer this question