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.
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local players = game:GetService( "Players" ) |
04 | local productID = 1006378151 |
05 |
06 | local function processReceipt (receiptInfo) |
07 |
08 | local player = players:GetPlayerByUserId(receiptInfo.PlayerId) |
09 | if not player then |
10 | --notg |
11 | --reee |
12 | return Enum.ProductPurchaseDecision.NotProcessedYet |
13 | end |
14 |
15 | if player then |
If you could help me out, please do.
if you want a player to keep gear after they die, you can put it inside their StarterGear so they respawn with it
1 | game.ServerStorage.cool:Clone().Parent = player.Backpack |
2 | 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
Instead of using a while loop, I would simply use an event which is made for cases such as this.
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local players = game:GetService( "Players" ) |
04 | local productID = 1006378151 |
05 |
06 | local function processReceipt (receiptInfo) |
07 |
08 | local player = players:GetPlayerByUserId(receiptInfo.PlayerId) |
09 | if not player then |
10 | --notg |
11 | --reee |
12 | return Enum.ProductPurchaseDecision.NotProcessedYet |
13 | end |
14 |
15 | if player then |
Using humanoid.Died
we can easily tell if a player has died, this is an event and can be use like this:
1 | game.Players.PlayerAdded:Connect( function (plr) |
2 | plr.CharacterAdded:Connect( function (char) |
3 | local humanoid = char:WaitForChild( "Humanoid" ) |
4 | humanoid.Died:Connect( function () |
5 | -- // Humanoid has died, do what ever |
6 | end ) |
7 | end ) |
8 | end ) |
I'd use the CharacterAdded event.
1 | game.Players.PlayerAdded:Connect:( function (player) |
2 | player.CharacterAdded:Connect( function () |
3 |
4 | YourTool:Clone().Parent = player.Backpack |
5 |
6 | end ) |
7 | 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.