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

Script not killing player after they purchase a product like it should?

The script is supposed to kill you when you purchase it. The leaderstats part works and so does the prompt to purchase. But it doesn't kill you.

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local RemoteEvent = game.ReplicatedStorage.PromptSkipStagePurchase
local productId = 1164319291

-- Prompt purchase
RemoteEvent.OnServerEvent:Connect(function(player)
	MarketplaceService:PromptProductPurchase(player, productId)
end)

-- Skip function
MarketplaceService.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == productId then
		
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		
		player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 -- Make the stage leaderstat go up by 1
		
		player.Character.Humanoid.MaxHealth = 0 -- Kills player so they respawn at next check point
	end
end

2 comments

0

Health*.

0

not maxHealth dude i think you mean Health

1 answer

✓ Accepted answer

You accidentally changed the MaxHealth, not the players actual Health

local MarketplaceService = game:GetService("MarketplaceService")
local RemoteEvent = game.ReplicatedStorage.PromptSkipStagePurchase
local productId = 1164319291

-- Prompt purchase
RemoteEvent.OnServerEvent:Connect(function(player)
    MarketplaceService:PromptProductPurchase(player, productId)
end)

-- Skip function
MarketplaceService.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == productId then

        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

        player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 -- Make the stage leaderstat go up by 1

        player.Character.Humanoid.Health = 0 -- Kills player so they respawn at next check point
    end
end

3 comments

0

it also should make a remote event to kill on the client just in case cause health is not replicated

0

^ No, add a playeradded event and get the player parameter, you can access the humanoid and to the health property

0

local scripts still have full access to the localplayer. so hp not being replicated wont be an issue. Granted the local script is a descendant of the local player or the local player's character

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