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

How to check if the player has "un-died"?

Asked by 8 years ago
01local player = game.Players.LocalPlayer
02 
03game.Workspace:WaitForChild(player.Name).Humanoid.Died:connect(function()
04    repeat wait() until game.Workspace[player.Name].Humanoid ~= nil
05 
06    if game.Workspace[player.Name].Humanoid ~= nil then
07        if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, 442799450) or player.Name == "uwot_m9" or player.Name == "Player1" or player.Name == "Ractrium" or player.Name == "Ravogan" then
08            --Double health
09            game.Workspace:WaitForChild(player.Name).Humanoid.MaxHealth = 200
10            game.Workspace:WaitForChild(player.Name).Humanoid.Health = 200
11        else
12        end
13 
14        if game.Workspace:WaitForChild(player.Name):WaitForChild("Health") then
15            game.Workspace:WaitForChild(player.Name).Health:Remove()
View all 21 lines...

There's my script, what is happening is it checks if the player is died, and repeats wait() until humanoid isn't nil, and checks if they own the gamepass and gives them double health, and inserts a modified health script, also.

But...none of it works, how do you check when the player is living again after he/she dies? Thanks for all help!

2 answers

Log in to vote
2
Answered by 8 years ago

You can use the CharacterAdded event to check when he respawns but this also checks for when his character is loaded into the game.

Ad
Log in to vote
1
Answered by 8 years ago

In general it is not good to change things like HP on the client side as this is secure information.

Events such as the humanoid died should also be done on the server. For players the CharacterAdded is used to setup properties for the player each time the character is added to the workspace so we don't need to check for when the player dies.

As currently this is done in a local script I have changed this into a server script:-

01local mps = game:GetService("MarketplaceService") -- so we dont waste time getting the service each time
02 
03-- a list of player who can get the HP with no gamepass
04-- this works as true is returned when found or nil when the player is not found nil in logic returns false
05local plrList = {
06    ["uwot_m9"] = true, ["Player1"] = true, ["Ractrium"] = true, ["Ravogan"] = true
07}
08 
09game.Players.PlayerAdded:connect(function(plr) -- add the ebent to the player when they join
10 
11    plr.CharacterAdded:connect(function(plrModel) -- this will run each time the spawn
12 
13        local plrNew = game.Players:GetPlayerFromCharacter(plrModel)
14 
15        -- it might be better to sore a value it the pass is present so we dont need to check each time
View all 40 lines...

Only one small change is that I have added a table. This will help when adding more people to check as you currently check for each name.

As this has be turned into a server script please comment if you need any more help in understanding how/why this works.

Hope this helps.

Answer this question