Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i create random death messages?

when someone dies they will receive a random message

local frame = script.Parent.Frame
local text = frame.TextLabel

msgTable = {}

msgTable[1] = "You died."
msgTable[2] = "You died!"
msgTable[3] = "You died?"
msgTable[4] = "You died..."
msgTable[5] = "Haha noob"
msgTable[6] = "Get rekt"
msgTable[7] = "Get shrekt"
msgTable[8] = "Better luck next time"
msgTable[9] = "That's one more death added..."
msgTable[10] = "Counting failures..."
msgTable[11] = "Error sytem shutting down."
msgTable[12] = "Error 404"
msgTable[13] = "E"
msgTable[14] = "What happened?"
msgTable[15] = "Huh.."
msgTable[16] = "Oh."

local randomMsg = msgTable[math.random(1, #msgTable)]

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
	
	text.Text = randomMsg
	frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quad",0.5,true)
	wait(1.5)
	frame.Position = 0.5,0,-0.5,0
	
end)

i dont see anything wrong but it does not work?

1 comment

0

At line 30 you need Udim2 For setting Position for example: Udim2.new(0.5,0,-0.5,0)

3 answers

✓ Accepted answer

To create one you need to have a local script in the starter gui, name it DeathMessages and then inside of the script put this

bc = BrickColor.new("Persimmon")

game.ReplicatedStorage.SendDeathMessage.OnClientInvoke = function(text)
	game.StarterGui:SetCore("ChatMakeSystemMessage",{
	Text = text,
	Font = Enum.Font.Cartoon,
	Color = bc.Color;
	FontSize = Enum.FontSize.Size96
	})
end

that will be to customize the message and then in workspace create a server script and name it DeathChatMessages, this one might be long!

--Messages
local DeathMessages = {"died"}  --you can add more if you like :D

--Actual script
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if script:FindFirstChild("SendDeathMessage") and script:FindFirstChild("DeathMessage") then
script:FindFirstChild("SendDeathMessage").Parent = game.ReplicatedStorage
script:FindFirstChild("DeathMessage").Parent = game.StarterGui
if player.Character:FindFirstChild("Humanoid") then
local hum = player.Character:FindFirstChild("Humanoid")
hum.Died:Connect(function()
local DeathMessage = DeathMessages[math.random(1,#DeathMessages)]
local Users = game.Players:GetChildren()
for i, User in pairs(Users) do
if game.ReplicatedStorage:FindFirstChild("SendDeathMessage") then
game.ReplicatedStorage.SendDeathMessage:InvokeClient(User, player.Name .. " " .. DeathMessage)
end
end
end)
end
elseif game.ReplicatedStorage:FindFirstChild("SendDeathMessage") and game.StarterGui:FindFirstChild("DeathMessage") then
if player.Character:FindFirstChild("Humanoid") then
local hum = player.Character:FindFirstChild("Humanoid")
hum.Died:Connect(function()
local DeathMessage = DeathMessages[math.random(1,#DeathMessages)]
local Users = game.Players:GetChildren()
print(player.Name .. " has died")
for i, User in pairs(Users) do
if game.ReplicatedStorage:FindFirstChild("SendDeathMessage") then
game.ReplicatedStorage.SendDeathMessage:InvokeClient(User, player.Name .. " " .. DeathMessage)
end
end
end)
end	
end
end)
end)

and then add a remote function in replicated storage and name it SendDeathMessage so the script can be functioned and to simply add more chat messages you can edit the first variable like this local DeathMessages = {"died", "did not do his job"} and so on hopefully this helped :D

Use a LocalScript

When you create a variables outside of the event, that variable was randomized just in a first time. After that is the same result because the value of this variable is the result of the first randomise.

local randomMsg = msgTable[math.random(1, #msgTable)] -- Wrong.

To fix this put the randomise on the Event

game:GetService('Players').LocalPlayer.Character.Humanoid.Died:Connect(function()
	
	text.Text = msgTable[math.random(1, #msgTable)]
	frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quad",0.5,true)
	wait(1.5)
frame.Position = UDim2.new(0.5,0,-0.5,0) -- Use UDim2 to change the position or the size.

end)

I recommand found the ScreenGui with the PlayerService (Players) and not with the Parent of the Instance.

local PlayerService = game:GetService('Players') -- You can see this Folder in the explorer.

local Player = PlayerService.LocalPlayer -- LocalScript only, this is you.

local PlayerGui = Player:WaitForChild('PlayerGui') -- Here is your ScreenGui

local ScreenGui = PlayerGui:WaitForChild('ScreenGui') -- Change "ScreenGui" to the name of yours

local frame = ScreenGui:WaitForChild('Frame')
local text = frame:WaitForChild('TextLabel')

Use WaitForChild to prevent errors.

Your script now:

local PlayerService = game:GetService('Players') -- You can see this Folder in the explorer.

local Player = PlayerService.LocalPlayer -- LocalScript only, this is you.
local PlayerGui = Player:WaitForChild('PlayerGui') -- Here is your ScreenGui
local ScreenGui = PlayerGui:WaitForChild('ScreenGui') -- Change "ScreenGui" to the name of yours

local frame = ScreenGui:WaitForChild('Frame')
local text = frame:WaitForChild('TextLabel')

local msgTable = {"You died.", "You died!", "You died?", "You died...", "Haha noob", "Get rekt", "Get shrekt", "Get shrekt", "Better luck next time", "That's one more death added...", "Counting failures...", "Error sytem shutting down.", "What happened?", "Error 404", "E", "Huh..", "Oh."}

Player.Character.Humanoid.Died:Connect(function()
	
	text.Text = msgTable[math.random(1, #msgTable)]
	frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Quad",0.5,true)
	wait(1.5)
	frame.Position = UDim2.new(0.5,0,-0.5,0) -- Use UDim2 to change the position or the size.
	
end)

Hope this help, to more questions put bellow on commentaries.

You would be better making use of table.insert or a set table

other than that i also see nothing wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.