Why Won't my DeathGui/PlayerGui Script Work?

hello, basically I made a script that is supposed to play sounds and a gui pops up when you die, but everything except the gui works. How do I fix this?

local db = false
local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not db then
			db = true
			Players.PlayerAdded:Connect(function(Player)
				Player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = true
			end)
			game.Workspace.FirstMap.KillSound:Play()
			game.Workspace.FirstMap.BassSound:Play()
			hit.Parent.Humanoid.Health = 0
		
			
			task.wait(7)
			db = false
		end
	end
end)

Using the playeradded event for this makes no sense. You can just get the player from the hit parameter using GetPlayerFromCharacter()

local db = false
local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not db then
			db = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			if plr then
				plr:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = true
			end
			game.Workspace.FirstMap.KillSound:Play()
			game.Workspace.FirstMap.BassSound:Play()
			hit.Parent.Humanoid.Health = 0
		
			
			task.wait(7)
			db = false
		end
	end
end)

Screen Guis do not have the visible property, only the enabled property. Enabled is basically the visible property counterpart for Screen Guis.

1 Like

Ohhh my bad. Did not knew i should have checked that before posting :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.