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

How to make server make chat when player dies?

this script in starter player scripts that doesnt put a chat when player dies, its also supposed to choose a random death chat, idk how to make work help plz

local plrName = game.Players.LocalPlayer.Name
local function chat(message)
if game.Players.LocalPlayer.Humanoid.Health == 0 then
	game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = message, Color = Color3.fromRGB(255, 255, 255), Font = Enum.Font.SourceSansBold})
end

local messages = {"(Server): bruh" .. plrName .. " just died", "(Server): " .. plrName .. " was grounded", "(Server): wow" .. plrName .. " is so bad at this game" }

while true do
	chat(messages[math.random(1, #messages)])
	end
	end

1 answer

The reason is doesn't work is because your trying to use a function inside of its own function. and the humanoid isn't inside of the player, its inside of player.character

here is a working one:

-- put this script inside startercharacterscripts                                      Click this   ^
local plrName = game.Players.LocalPlayer.Name
function chat(message)
		game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = message, Color = Color3.fromRGB(255, 255, 255), Font = Enum.Font.SourceSansBold})
end

local messages = {"(Server): bruh" .. plrName .. " just died", "(Server): " .. plrName .. " was grounded", "(Server): wow" .. plrName .. " is so bad at this game" }

script.Parent.Humanoid.Died:Connect(function()
	chat(messages[math.random(1, #messages)])
end)

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