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.**
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
Thanks,
John
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..
Thank you for your answer, but it still didn't work :/