Ad
Log in to vote
0

Checking if a Player is dead.?

Asked by 1 year ago
Edited 1 year ago

Hi, I'm trying to make a script so that if they buy a dev product they get a coil, but if they die, they get the coil again. No matter what I do I can't get it to award the coil when they die. I don't want to use a game pass though.

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local productID = 1006378151

local function processReceipt (receiptInfo)

    local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        --notg
        --reee
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if player then
        game.ServerStorage.cool:clone().Parent = player.Backpack ---Award it as soon as they buy it.

        while true do ---A while true loop to check if they are dead.


        end

    end


    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

If you could help me out, please do.

0
Where is the script located inside of? AlmostADemon 50 — 1y
0
use Humanoid.Died misha123 83 — 1y

4 answers

Log in to vote
2
Answered by
Elyzzia 1289 Moderation Voter
1 year ago

if you want a player to keep gear after they die, you can put it inside their StarterGear so they respawn with it

game.ServerStorage.cool:Clone().Parent = player.Backpack
game.ServerStorage.cool:Clone().Parent = player.StarterGear

keep in mind, you have to clone it into BOTH their Backpack and their StarterGear, or else they won't get it until they respawn

0
Thanks. stickymirro511 61 — 1y
Ad
Log in to vote
5
Answered by
phxntxsmic 2217 Moderation Voter Community Moderator
1 year ago
Edited 1 year ago

Instead of using a while loop, I would simply use an event which is made for cases such as this.

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local productID = 1006378151

local function processReceipt (receiptInfo)

    local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        --notg
        --reee
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if player then
        game.ServerStorage.cool:clone().Parent = player.Backpack ---Award it as soon as they buy it.

       player.CharacterAdded:Connect(function()
            game.ServerStorage.cool:clone().Parent = player.Backpack -- Every time the player spawns, they receive the item.
       end)

    end


    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt
Log in to vote
2
Answered by 1 year ago
Edited 1 year ago

Using humanoid.Died we can easily tell if a player has died, this is an event and can be use like this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
      local humanoid = char:WaitForChild("Humanoid")
        humanoid.Died:Connect(function()
           -- // Humanoid has died, do what ever
   end)
 end)
end)
Log in to vote
2
Answered by 1 year ago
Edited 1 year ago

I'd use the CharacterAdded event.

game.Players.PlayerAdded:Connect:(function(player)
    player.CharacterAdded:Connect(function() 

        YourTool:Clone().Parent = player.Backpack

    end)
end)

You can swap the while loop for this as this fires only when the event happens. This eliminates unnecessary looping which can sometimes cause performance issues.

0
That's detecting when they spawn, not when they die. WideSteal321 769 — 1y

Answer this question