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

Changing Humanoid properties after a DevProduct is purchased?

Asked by 6 years ago

I literally just asked a question but I'm making a game and sadly I keep running into issues.

So this would increase the purchaser's WalkSpeed by 7 once purchased. Here is the total script -

local MartketplaceService = game:GetService('MarketplaceService')
local devproductid = 84718040
local devproductid2 = 84717927
local devproductid3 = 84715500
MartketplaceService.ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren())do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == devproductid2 then
                player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
            end
            if receiptInfo.ProductId == devproductid then
                player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 3
            end
            if player.leaderstats.Stage.Value > 15 then
                player.leaderstats.Stage.Value = 15
            end
            if receiptInfo.ProductId == devproductid3 then
                player:FindFirstChild("Character").Humanoid.WalkSpeed = player:FindFirstChild("Character").Humanoid.WalkSpeed + 7
            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

But this is the part that is not working and causing me problems. The error that is popping up is "Line 18 is indexing a nil value" -

            if receiptInfo.ProductId == devproductid3 then
                player:FindFirstChild("Character").Humanoid.WalkSpeed = player:FindFirstChild("Character").Humanoid.WalkSpeed + 7
            end
0
The player does not have a child called Character User#5423 17 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Remove :FindFirstChild("Character")

It is just player.Character.

So in conclusion, your code code that is indexing nil should be:

if receiptInfo.ProductId == devproductid3 then
    player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed + 7
end

Sorry if this isn't well explained, I am in a rush, hope this solved your problem though! :)

0
It's explained very well, no worries. Also it worked so thank you. noob1126 34 — 6y
Ad

Answer this question