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

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

Asked by
CodeWon 181
3 years ago

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
0
Health*. Ziffixture 6913 — 3y
0
not maxHealth dude i think you mean Health mroaan 95 — 3y

1 answer

Log in to vote
4
Answered by 3 years ago

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
0
it also should make a remote event to kill on the client just in case cause health is not replicated kepiblop 124 — 3y
0
^ No, add a playeradded event and get the player parameter, you can access the humanoid and to the health property Xapelize 2658 — 3y
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 NGC4637 602 — 3y
Ad

Answer this question