Help with death messages script!

  1. What do you want to achieve?
    Making the GUI appear with randomized text from the specific table, once the player has died.
  2. What is the issue?
    The GUI doesn’t appear and the text doesn’t change.
  3. What solutions have you tried so far?
    I tried reparenting the GUI through the script, and I tried moving the script from starterGui to StarterPlayerScripts* and even StarterCharacterScripts, Nothing worked!
    I’m trying to make death messages for my upcoming obby game (Concepts will be shown in a different topic), and I got really confused with the fact that the GUI doesn’t even appear at PlayerGui.

Here is the code (Local script):

local text = {
	"This is the first death message in this game!",
	"Make sure to like the game if you think it's hard!",
	"BeepBopBeep, respawning in 3.75 seconds.",
	"+1 death",
	"How did you get this message?",
	"Follow the game to be notified when a new update comes out!",
	"You died!",
	"OOF!",
	"Try again, I believe in you!",
	":(",
	":)",
	"00110000 00110100 00110000 00110010 00110010 00110001",
	"Did you know that there is only 7.6923076923077% chance of getting this death message!?"
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Humanoid = char:FindFirstChild("Humanoid")
		Humanoid.Died:Connect(function()
			local number = math.random(1, #text)
			game.ServerStorage.DeathMessages.Parent = game.Players.LocalPlayer.PlayerGui
			game.ServerStorage.DeathMessages.Frame.TextLabel.Text = text[number]
			wait(5)
			game.ServerStorage.DeathMessages.Frame.TextLabel.Text = ""
			game.ServerStorage.DeathMessages.Parent = game.Players.LocalPlayer.PlayerGui
		end)
	end)
end)

If anyone can help, I’ll appreciate it alot.

game.ServerStorage.DeathMessages.Frame.TextLabel.Text = text[number]
this line your changing the text in the server storage
not the playergui

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Humanoid = char:FindFirstChild("Humanoid")
		Humanoid.Died:Connect(function()
			local number = math.random(1, #text)
			local DeathGuiClone = game.ServerStorage.DeathMessages:Clone()
			DeathGuiClone.Frame.TextLabel.Text = text[number]
			DeathGuiClone.Parent = game.Players.LocalPlayer.PlayerGui
			wait(5)
			DeathGuiClone:Destroy()
		end)
	end)
end)

use this instead

2 Likes

Oh dear everything

Try not to implement CharacterAdded or PlayerAdded Events inside LocalScripts please

Don’t define the LocalPlayer in a Server Script, but instead reference the Player’s Gui inside your PlayerAdded Event:

local text = {
	"This is the first death message in this game!",
	"Make sure to like the game if you think it's hard!",
	"BeepBopBeep, respawning in 3.75 seconds.",
	"+1 death",
	"How did you get this message?",
	"Follow the game to be notified when a new update comes out!",
	"You died!",
	"OOF!",
	"Try again, I believe in you!",
	":(",
	":)",
	"00110000 00110100 00110000 00110010 00110010 00110001",
	"Did you know that there is only 7.6923076923077% chance of getting this death message!?"
}

game.Players.PlayerAdded:Connect(function(plr)
    local PlayerGui = plr:WaitForChild("PlayerGui")

	plr.CharacterAdded:Connect(function(char)
		local Humanoid = char:FindFirstChild("Humanoid")
		Humanoid.Died:Connect(function()
			local number = math.random(1, #text)
            local GuiClone = game.ServerStorage.DeathMessages:Clone()
            GuiToClone.Parent = PlayerGui
            GuiToClone.Frame.TextLabel.Text = text[number]
			wait(5)
			GuiToClone:Destroy()
		end)
	end)
end)

Also your “DeathMessages” Gui would only be parented to & from back, I’d recommend adding a couple more variables to organize the script a bit better

(And yes change it to a ServerScript and put it in ServerScriptService I didn’t see that one)

1 Like

from what i see you are trying to access ServerStorage with a localscript, SeverStorage and ServerScriptService can only be accessed with a normal script. I suggest you change the script to a normal one as it still should work the same.

or he could just move it to replicated storage

You’re right, I forgot to change it, but that’s not the only problem I have. Thank you for telling me tho! :slight_smile:

store the gui in replicated storage or in starter Guis and activate it when necessary

What’s the GuiToClone, the screenGui?

Yeah, it’s just a variable to clone it to the Player’s Gui then after 5 seconds it’ll be destroyed

Unless if you want to keep the DeathMessages Gui upon death?

You’re both correct, I’ll move it to replicated storage!

Okay! I’ll try that script :slight_smile:

@Jackscarlett I tested the script and it was not working, and I got no errors as well.

The script should be put inside ServerScriptService, don’t put it in ReplicatedStorage otherwise it won’t run

I was putting it as a local script in StarterCharacterScripts, and I also tried it in StarterPlayerScripts and StarterGui.

It should be a Server Script, put inside ServerScriptService

If you put it anywhere else other than there or the workspace, the script will more than likely not work

Especially if you have PlayerAdded & CharacterAdded events

1 Like

It still doesn’t work, what do I do?

Are you getting any errors on the Output at all?

as it looks like, the output is completely empty.

Hm, alright

Can you try this script and see what outputs?

local text = {
	"This is the first death message in this game!",
	"Make sure to like the game if you think it's hard!",
	"BeepBopBeep, respawning in 3.75 seconds.",
	"+1 death",
	"How did you get this message?",
	"Follow the game to be notified when a new update comes out!",
	"You died!",
	"OOF!",
	"Try again, I believe in you!",
	":(",
	":)",
	"00110000 00110100 00110000 00110010 00110010 00110001",
	"Did you know that there is only 7.6923076923077% chance of getting this death message!?"
}

game.Players.PlayerAdded:Connect(function(plr)
    print("Player added")
    local PlayerGui = plr:WaitForChild("PlayerGui")

	plr.CharacterAdded:Connect(function(char)
        print("Character added")
		local Humanoid = char:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
            print("Ouch")
			local number = math.random(1, #text)
            local GuiToClone = game.ServerStorage.DeathMessages:Clone()
            GuiToClone.Parent = PlayerGui
            GuiToClone.Frame.TextLabel.Text = text[number]
			wait(5)
			GuiToClone:Destroy()
		end)
	end)
end)

A really tiny typo here

and

Replace GuiClone with GuiToClone.

2 Likes