Sctipt not showing gui after death after many second

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = Players:GetPlayerFromCharacter(char)
local deathAnim = hum:LoadAnimation(script:WaitForChild("DeathAnim"))

hum.BreakJointsOnDeath = false
local dead = false

function deathCheck(health)
	if health <= 0 and not dead then
		dead = true

		local root = char:FindFirstChild("HumanoidRootPart")
		if root then
			root.Anchored = true
		end
		
		for _, part in ipairs(char:GetChildren()) do
			if part:IsA("BasePart") then
				part.CanCollide = false
			end
		end

		deathAnim.Looped = false
		deathAnim:Play()

		task.delay(1, function()
			local splat = workspace:FindFirstChild("DeathSplat")
			if splat and splat:IsA("Sound") then
				local clone = splat:Clone()
				clone.Parent = char:FindFirstChild("Head") or char
				clone:Play()
				Debris:AddItem(clone, 5)
			end
		end)

		task.delay(2, function()
			local deathSound = workspace:FindFirstChild("DeathSound")
			if deathSound and deathSound:IsA("Sound") then
				local clone = deathSound:Clone()
				clone.Parent = char:FindFirstChild("Head") or char
				clone:Play()
				Debris:AddItem(clone, 5)
			end
		end)

		task.delay(4, function()
			local localPlayer = Players.LocalPlayer
			if localPlayer and localPlayer == player then
				local gui = localPlayer:WaitForChild("PlayerGui", 2)

				for _, child in ipairs(gui:GetChildren()) do
					if child:IsA("ScreenGui") and child.Name ~= "Spectate_after_death" then
						child.Enabled = false
					end
				end

				local introGui = gui:FindFirstChild("IntroGui")
				if introGui then
					introGui.Enabled = true
					task.delay(5, function()
						introGui.Enabled = false
					end)
				end
			end
		end)

		task.delay(10, function()
			if root then
				root.Anchored = false
			end
			script:Destroy()
		end)
	end
end

hum.HealthChanged:Connect(deathCheck)

1 Like

Sorry i just set delay.task (1) in video

Is this inside of a Local Script or a Server Script?

Hello please avoid misusing closures aswell as “spamming” task thread.
Could you please provide information such as:

  • location of a script?
  • behavior/system you want to archive?

I will assume that its a StarterCharacterScript

IDk i tried fixing your script a little:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local splat = workspace:WaitForChild("DeathSplat")::Sound
local deathSound = workspace:WaitForChild("DeathSound")::Sound
local localPlayer = Players.LocalPlayer
local gui = localPlayer:WaitForChild("PlayerGui")::PlayerGui


local char = script.Parent::Model
local hum = char:WaitForChild("Humanoid")::Humanoid
local animator = hum:WaitForChild("Animator")::Animator
local player = Players:GetPlayerFromCharacter(char)::Player
local deathAnim = animator:LoadAnimation(script:WaitForChild("DeathAnim")::Animation)
deathAnim.Looped = false

hum.BreakJointsOnDeath = false
local dead:boolean = false
local head = char:FindFirstChild("Head") or char

local function SetProperty(a,b,c)
	a[b]=c
end



local function deathCheck(health:number):()
	if health > 0 or dead then return end
	dead = true

	local root = char:FindFirstChild("HumanoidRootPart")::Part?
	if root then root.Anchored = true end

	for _, part in char:GetChildren() do
		if not part:IsA("BasePart") then continue end
		part.CanCollide = false
	end


	deathAnim:Play()

	task.wait(1)

	local clone = Instance.fromExisting(splat)
	clone.Parent = head
	clone:Play()
	Debris:AddItem(clone, 5)
	task.wait(2)

	local clone = Instance.fromExisting(deathSound)
	clone.Parent = head
	clone:Play()
	Debris:AddItem(clone, 5)



	task.wait(4)

	if localPlayer and localPlayer == player then
		
		for _, child in gui:GetChildren() do
			if child:IsA("ScreenGui") and child.Name ~= "Spectate_after_death" then
				child.Enabled = false
			end
		end

		local introGui = gui:FindFirstChild("IntroGui")
		if introGui then
			introGui.Enabled = true
			task.delay(5, SetProperty,introGui,"Enabled",false)
		end
	end


	task.wait(10)
	if root then
		root.Anchored = false
	end
	script:Destroy()
end

hum.HealthChanged:Connect(deathCheck)

Follow up: if its on a server script, you cannot retrieve LocalPlayer from the server

Server, but i fixed rn, cuz i do local+server with remote, I just realized that they can be connected

You have to explain

Bruuhhh
Like… dude…
kmon did i fix your script nothing? :skull_and_crossbones:

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