Gui Appear on death

I made a respawn GUI that if you click on it respawns the character but I don’t how to make it appear when the player dies. I made one with the script on the API Site But It doesn’t work. Here is the script:

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			game.StarterGui.Respawn.Enabled = true
		end)
	end)
end)

But I made it a local script and placed it in StarterCharacterScripts but it doesn’t work. What do I do?

2 Likes

How the heck does the API Site manage to mess up that badly, the StarterGui is referenced by the server only

Get the PlayerGui instead, which is replicated across the client side:

game.Players.PlayerAdded:Connect(function(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")
    Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Died:Connect(function()
			PlayerGui.Respawn.Enabled = true
		end)
    end)
end)

Also this shouldn’t be a LocalScript, change it to a Server Script please inside ServerScriptService

3 Likes

I just tried the script but It doesn’t work. Is it an Error because it doesn’t show in the output?

Forgot to mention this oops.mp3

It’s better to put it as a child of the ScreenGui that should be enabled, given that the ScreenGui has ResetOnSpawn Enabled, because even if proper fixing was in place, it’s better to do it locally since only the client has to care if it’s enabled or not, server doesn’t need to be involved, and to remove some unnecessary event creation since you’re making 3 events for the ScreenGui when only 1 is needed if you directly reference the humanoid locally, unless PlayerAdded and CharacterAdded were used before in other scripts in which you can just combine the 2.

Here’s something that should work, localscript in the ScreenGui that has to be enabled on death

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	script.Parent.Enabled = true
end)
8 Likes

You can put this script in Workspace btw, it’s easier I think and it won’t lag the game(I’m not telling that the other ones are laggy.)

local Players = game:GetService("Players")




local function onCharacterAdded(character)

	character:WaitForChild("Humanoid")


	character.Humanoid.Died:Connect(function()

		local player = Players:GetPlayerFromCharacter(character)
		local playerGui = player:FindFirstChildOfClass("PlayerGui")


		if playerGui then

			local GUI = playerGui.ScreenGui
			if GUI then
				GUI.Enabled = true
			end
		end
	end)
end


Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)

2 Likes

oh, it’s 3 years…I didn’t see it…