Humanoid.Died Issues with playerGuis

  1. What do you want to achieve? Keep it simple and clear!
    Make GUI disappear after time limit
  2. What is the issue? Include screenshots / videos if possible!

If the player respawns, the GUI wont be disabled

Also the GUI appears for the first player then the second because of the timer. I dont know how i would fix that.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Dev fourms

Code:

script.Parent:FindFirstChild("Humanoid").Died:Connect(function()
	for i, player in pairs(game:GetService("Players"):GetPlayers())do
		player.PlayerGui:WaitForChild("NotificationUI").Enabled = true
		
		if script.Parent:FindFirstChild("IsNPC") and player and player.Character then
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "NPC" ..script.Parent.Name.. " Has Died!"
		else
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "Player " ..script.Parent.Name.. " Has Died!"
		end
		
		task.wait(2)
		
		player.PlayerGui:WaitForChild("NotificationUI").Enabled = false
	end
end)

Video:

If you need any more info just ask.

Here try this:

script.Parent:FindFirstChild("Humanoid").Died:Connect(function()
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		-- Make sure the player has a PlayerGui and NotificationUI
		local playerGui = player:FindFirstChild("PlayerGui")
		if playerGui then
			local notificationUI = playerGui:FindFirstChild("NotificationUI")
			if notificationUI then
				-- Show the notification
				notificationUI.Enabled = true
				notificationUI.NotificationFrame.NotificationLabel.Text =
					(if script.Parent:FindFirstChild("IsNPC") then "NPC " else "Player ") .. script.Parent.Name .. " Has Died!"

				task.wait(2)

				-- Get the UI again in case the player respawned
				local updatedUI = playerGui:FindFirstChild("NotificationUI")
				if updatedUI then
					updatedUI.Enabled = false -- Hide the notification after 2 seconds
				end
			end
		end
	end
end)

When a player dies and respawns, Roblox resets their screen (PlayerGui). This means the old notification you turned on disappears, and a new one gets made. But your script is still trying to turn off the old one, which doesn’t exist anymore. So, after waiting, the new notification stays on instead of disappearing.

Edit: If it does not work please let me know

1 Like

use task.delay() so it appears for all players at the same time

script.Parent:FindFirstChild("Humanoid").Died:Connect(function()
	for i, player in pairs(game:GetService("Players"):GetPlayers())do
		player.PlayerGui:WaitForChild("NotificationUI").Enabled = true
		
		if script.Parent:FindFirstChild("IsNPC") and player and player.Character then
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "NPC" ..script.Parent.Name.. " Has Died!"
		else
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "Player " ..script.Parent.Name.. " Has Died!"
		end
		task.delay(2,function()	
		    player.PlayerGui:WaitForChild("NotificationUI").Enabled = false
        end)
	end
end)
2 Likes


If you respawn while the GUI is still enabled, the GUI wont disappear still : (
Thanks for helping anyhow

1 Like

Thanks! This fixed my issue of not all players enabling the GUI at once.

Im going to try to fix my issue now of the GUI not disabling after respawn.

1 Like

Hey, I edited the code in my last reply. See if that works?

1 Like

Same issue again.

Though the code is looking 100X better i gotta say. Nice work

1 Like

I am going to start testing this myself, I will let you know when I find a fix.

1 Like

Alr Thanks.

I will also try to find my own solution aswell

script.Parent:FindFirstChild("Humanoid").Died:Connect(function()
	for i, player in pairs(game:GetService("Players"):GetPlayers())do
		player.PlayerGui:WaitForChild("NotificationUI").Enabled = true
		
		if script.Parent:FindFirstChild("IsNPC") and player and player.Character then
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "NPC" ..script.Parent.Name.. " Has Died!"
		else
			player.PlayerGui:WaitForChild("NotificationUI").NotificationFrame.NotificationLabel.Text = "Player " ..script.Parent.Name.. " Has Died!"
		end 

        print("enabled")

		task.delay(2,function()	
		    player.PlayerGui:WaitForChild("NotificationUI").Enabled = false
            print("disabled")
        end)
	end
end)

see what prints


So on being alive it enables it then disapears.

Video:

what’s the issue with this? char

Its supossed to go off when the player Dies?

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Died:Connect(function()
				-- Notify all players
				for _, otherPlayer in pairs(game:GetService("Players"):GetPlayers()) do
					local playerGui = otherPlayer:FindFirstChild("PlayerGui")
					if playerGui then
						local notificationUI = playerGui:FindFirstChild("NotificationUI")
						if notificationUI then
							-- Enable notification
							notificationUI.Enabled = true
							notificationUI.NotificationFrame.NotificationLabel.Text = "Player " .. player.Name .. " Has Died!"
						end
					end
				end

				-- Wait 2 seconds, then disable the notification for all players
				task.wait(2)
				for _, otherPlayer in pairs(game:GetService("Players"):GetPlayers()) do
					local playerGui = otherPlayer:FindFirstChild("PlayerGui")
					if playerGui then
						local notificationUI = playerGui:FindFirstChild("NotificationUI")
						if notificationUI then
							notificationUI.Enabled = false
						end
					end
				end
			end)
		end
	end)
end)

This has worked for me, please make sure it is a script in serverscriptservice

Hey you got it working! Thanks alot for the help, been on this for awhile or so.

The GUI works properly now.

1 Like

Hey, sorry for being late to the party!

I couldn’t help but notice that the solutions are very long, and keeping track of each player on the server isn’t advisable. This can be solved by using a simple client-server - server-clients solution.

Using the server to enable UI for a player is also unnecessary, as the client is usually in charge of visuals, and it puts strain on the server as well. (Again, use the client-server server-client method. Make sure to do checks though!)

To answer your question of the UI resetting on respawn, just check the ResetOnSpawn (In the ScreenGui class) property to false.

P.S, :FireAllClients()

Thanks for the advice, i will take it in mind.

Also ResetOnSpawn was turned off.
PS: I had tested all the scripts given with it on and off to make sure