What do you want to achieve?
Making the GUI appear with randomized text from the specific table, once the player has died.
What is the issue?
The GUI doesn’t appear and the text doesn’t change.
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)
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)
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.
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)