Problems with this LocalScript

Alright, this is your script, which I have on StarterGui:
image
image
These should be the ScreenGui properties:
image

Now, putting it to the test:

I don’t know what else to say.

I put the script in StarterPlayerScripts.
Could that be a problem?

That is working because startergui resets every time a player dies

Forgot about that. Yeah, I see what they mean now.

To make it work under starterplayerscripts

above the humanoid died event you would need a character added event as because the died connection disconnects itself due to the humanoid being destroyed

ok now why does everybody start replying :skull:

The problem is a new character is created when a player dies so you need to use CharacterAdded

1 Like

Or you can use StarterCharacterScripts instead

Put this in local player as a local script
playerGui.LolGui.Enabled = Humanoid.Died:GetFirst()

If you use the exact code in StarterCharacterScripts, it should work without an issue

it doesn’t even function there

I have modified the code to remove when you respawn
pls be nice this is the smallest i can get the code

local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
    playerGui.LolGui.Enabled = true

Can you show the whole code so I can see why it wont work?

StarterPlayerScripts:

local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	playerGui.LolGui.Enabled = true
	wait(3)
	playerGui.LolGui.Enabled = false
end)

in the GUI:

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

local text = { 
	"Lol ded",
	"Parented" .. plr.Name .. "to nil",
	"pls no rage",
	"oof",
	"Definition of pain",
	"RIP"
}

local textLabel = script.Parent.TextLabel

textLabel.Text = text[math.random(1, #text)]

Here:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local PlayerGui = LocalPlayer.PlayerGui
local LolGui = PlayerGui:WaitForChild("LolGui")
local TextLabel = LolGui:WaitForChild("TextLabel")

local text = { 
	"Lol ded",
	"Parented " .. LocalPlayer.Name .. " to nil",
	"pls no rage",
	"oof",
	"Definition of pain",
	"RIP"
}

Humanoid.Died:Connect(function()
	TextLabel.Text = text[math.random(1, #text)]
	LolGui.Enabled = true
	task.delay(3, function()
		LolGui.Enabled = false
	end)
end)

This should work under StarterCharacterScripts. Make sure the TextLabel is directly below LolGui. Your current script does not randomize the text, so I fixed that for ya!

Oh my goodness, thank you!
Exactly what I wanted!

I don’t even know why I added “Players.PlayerAdded:Wait()” or “CharacterAdded:Wait()” when this literally runs after Character is added, guess it’s just habit.

No probs. Make sure you copy the script again, I’m stupid and broke it.

Can’t you just have this in the gui?

local players = game:GetService("Players")

local client = players.LocalPlayer
local character = client.Character
local humanoid = character:WaitForChild("Humanoid")

local screenGui = script.Parent

local randomText = { 
	"Lol ded",
	"Parented" .. client.Name .. "to nil",
	"pls no rage",
	"oof",
	"Definition of pain",
	"RIP"
}

humanoid.Died:Connect(function()
	screenGui.Enabled = true
	screenGui.TextLabel.Text = randomText[math.random(1, #randomText)]
end)

Why do you need 2 scripts for this?

Just a beginners mistake, don’t worry about it now, it’s solved.

Also I’m pretty sure the ScreenGui automatically disappears since it’s destroyed on ResetOnSpawn, so there was no need for the task.delay. I don’t know why I did it either way, just stupid perhaps.