Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make server make chat when player dies?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question