This script is not working


wait()
local Load = game:GetService("ReplicatedStorage"):FindFirstChild("FalconLoadingV1")
local Death = game:GetService("ReplicatedStorage"):FindFirstChild("FalconDeathV1")

local Player = game:GetService("Players").LocalPlayer

function deathScreen(gui)
	local Clone = Death:Clone()
	wait(game:GetService("Players").RespawnTime)
	Clone:Destroy()
end

function loadScreen(gui)
	Load:Clone().Parent = gui
end

Player.Character.Humanoid.Changed:Connect(function()
	if Player.Character:WaitForChild("Humanoid").Health == 0 then
		deathScreen(Player:WaitForChild("PlayerGui"))
	end
end)

game:GetService("Players").PlayerAdded:Connect(function(plr)
	deathScreen(plr:WaitForChild("PlayerGui"))
end)

2 Likes

What exactly is the issue? Does it error?

Also, you’re using Players.PlayerAdded on the client.

1 Like

Nope, dosent give error. The gui’s dont show…

True, I passed it down from a module.

Ok, so I see a few issues:

  1. You don’t have to put wait() at the beginning of the script
  2. You have to account for when the player dies, you’d have to reconnect to a new humanoid
  3. For the death guis to disappear, just turn on ResetOnSpawn for the ScreenGuis, it’ll be auto-deleted when they respawn

I cleaned up your code:

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local LocalPlayer = Players.LocalPlayer
local Load = ReplicatedStorage:WaitForChild('FalconLoadingV1') -- use "WaitForChild" because it waits for it to load if it already hasn't
local Death = ReplicatedStorage:WaitForChild('FalconDeathV1')

local function OnDied() -- function used to detect when the player dies
  local Clone = Death:Clone()
  Clone.Parent = LocalPlayer:WaitForChild('PlayerGui')
end

local function OnCharacterAdded(character) -- function used to get the player's character when it loads
   local Humanoid = character:WaitForChild('Humanoid')
   Humanoid.Died:Connect(OnDied) -- connect the died function to the humanoid died event
end

LocalPlayer.CharacterAdded:Connect(OnCharacterAdded) -- connect the event to the character added function
Load:Clone().Parent = LocalPlayer:WaitForChild('PlayerGui') -- enable load screen by default
1 Like

Hmm, everything good except the deathgui… not loading…

It errors it and says:

Players.funnyfunns.PlayerGui.FalconLoadingV1.LocalScript:6: attempt to index nil with ‘FindFirstChild’

That’s an error in a different script you have

local function OnDied() 
  local Clone = Death:Clone()
  Clone.Parent = LocalPlayer:WaitForChild('PlayerGui')
  print('player died') -- add this to the function to see if it runs, if it does then the gui might be disabled
end

Oh thank you! It will be good for my model!

You never described your goal or error - are you trying to make a death GUI that will show upon death?