Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Checking if a Player is dead.?

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.

2 comments

0

Where is the script located inside of?

0

use Humanoid.Died

4 answers

✓ Accepted answer

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

1 comment

0

Thanks.

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

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)

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.

1 comment

0

That's detecting when they spawn, not when they die.

This discussion is preserved as it was. New answers, comments, and votes are closed.