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

How do I make a kill message?

Asked by 8 years ago

I want to know what to have in a script so when somebody dies it prints "Dead". EX: (but it does not work)

if game.Workspace.Player1.Humanoid.Health == 0 then
    print("Dead")
end

I used player1 because that is what the player shows up as in Roblox Studio test mode.

0
Use the Lua icon to place your code in. RAYAN1565 691 — 8y
0
Thanks for the accept! <3 User#11440 120 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

FlaminSparrow and Necrorave's answer would work, but there's a much better way of doing this.

I'm mostly just building upon their answers. Great job guys!

Instead of using a LocalScript in StarterGui, use a regular script in ServerScriptService.

"But how?"

Use embedded functions!

You can do this by connecting function within other functions. Here's my solution,

--Normal Script in ServerScriptService
game.Players.PlayerAdded:connect(function(plr)--Player Added
    plr.CharacterAdded:connect(function(char)-- Character Added
        local Humanoid = char:WaitForChild("Humanoid")--Character's Humanoid
        Humanoid.Died:connect(function()--Character Died
            print(plr.Name.." Died")--Prints player's name Died
        end)
    end)
end)

I understand you might not know how this works, but learn from it.

When the function happens, it gives you a variable like the player, or player's character. These variables can be used to make new functions.

That should do it

Good Luck!

Ad
Log in to vote
1
Answered by 8 years ago

Best option i can think of right now, is to place a server(if you're using FE)/local script inside the player's StarterPack/StarterGui.

local Player = script.Parent.Parent
repeat wait() until Player.Character ~= nil
local Character = Player.Character
local Humanoid = Character.Humanoid

Humanoid.Died:connect(function()
    print"Dead"
end
0
This is an okay answer, I'm going to add a few things. User#11440 120 — 8y
Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
8 years ago

I would recommend you use the Died event.

This event will wait for the humanoid you choose to die, then it would proceed to run whatever script you ask it to upon said death.

Example:

game.Workspace.Player1.Humanoid.Died:connect(function()

    print("Player1 has died!")

end)

Keep in mind, when using "Events" in your scripts to followup with a :connect in order to "connect" a script to that event.

If you have any other questions let me know!

Resources: Died event Wiki

0
Yep, this would work :P User#11440 120 — 8y

Answer this question