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.
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!
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
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