Need help fixing my script

Hello, I Made a script that hides the player after dying or destroys the player from Workspace after dying, so the script is working good but the problem that it made another script i made doesn’t work, can anyone help??

the destroying after dying script

local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild(“Humanoid”)

	humanoid.Died:Connect(function()
		-- Wait for 1 second before removing the character from the workspace
		wait(1)
		-- Remove the character from the workspace
		character.Parent = nil
	end)
end)

end)

the script that doesn’t work anymore after making the destroying script

local player = game.Players.LocalPlayer
local gui = script.Parent
local frame = gui:WaitForChild(“DeathScreen”) – Change “Frame” to your frame’s name if different

– Function to handle when player dies
local function onPlayerDied()
frame.Visible = true
end

– Function to connect player character events
local function onCharacterAdded(character)
frame.Visible = false – Hide the frame when the player respawns
local humanoid = character:WaitForChild(“Humanoid”)
humanoid.Died:Connect(onPlayerDied)
end

– Connect the CharacterAdded event
player.CharacterAdded:Connect(onCharacterAdded)

– Check if the character already exists when the game starts
if player.Character then
onCharacterAdded(player.Character)
end

Is there an output error at all?

1 Like

no there’s no error in output.

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid
local gui = script.Parent
local frame = gui.DeathScreen

if frame.Visible then frame.Visible = false end

local function characterAdded()
frame.Visible = false
end

local function onPlayerDied()
frame.Visible = true
player.CharacterAdded:Connect(characterAdded)
end

Humanoid.Died:Connect(onPlayerDied)
1 Like

don’t have the characteradded event inside onPlayerEvent. Its just gonna keep spawning multiple events when the player dies. Maybe replace CharacterAdded:Connect to CharacterAdded:Once

1 Like

Thanks for the script! but it needs some changes to work, Thanks anyways :smile:

Thanks so much for helping me fixing it :grin: