Random death message popup

Okay, so i have a pretty stupid game where there is a default baseplate and a hole in the floor, and there is a sign telling you not to jump into said hole, and if you do you get stopped by a barrier that kill you, it pops up on onscreen gui with text, i wanna know how to make the death messages random, the script is below.

Popup = script.Parent.Popup
Ready = true
function onTouch(hit)
local h = hit.Parent:FindFirstChild(“Humanoid”)
if h ~= nil and Ready == true then
Ready = false --Nopes.
local plyr = game.Players:FindFirstChild(h.Parent.Name)
local c = Popup:clone()
c.Parent = plyr.PlayerGui
local s = Sound:clone()
s.Parent = plyr
wait(2)
c:remove()
s:remove() .
wait(.1)
Ready = true
end
end

script.Parent.Touched:connect(onTouch)

2 notes:

1.Use task.wait instead of wait [it affects performance].

2.Do not use remove, use destroy instead. [or GarbageService].

Now about the problem,
You can have a table of messages, example:

local messages = {
   "Try better, newbie!";
   "Wasted";
}

And now, to get a random message out of this table -

local randomMessage = messages[math.random(1,#messages)]

You then can simply imply that randomMessage to a textlabel or whatever it is as the message.

1 Like

How do i connect it to my text label gui?

A simple script can do this:

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local messages = {
   "Try better, newbie!";
   "Wasted";
}

humanoid.Died:Connect(function()
local NewMessage = messages[math.random(1, #messages)]
script.Parent.TextLabel.Text = NewMessage
end)
1 Like

Thank you, i will try this and let you know