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

Why is my script that is located in ServerScriptStorage not giving my character a tool?

Asked by 4 years ago

When I purchase a developer product in my game it gives me the receipt and everything however it doesn't give me the popcorn/product. What is wrong with my script?

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local players = game.Players:GetPlayers()
for i=1,#players do
if players[i].UserId == receiptInfo.PlayerId then
    local RS = game:GetService("ReplicatedStorage")
    local item = RS:WaitForChild("Popcorn")
    local cloned = item:Clone()
    local player = game.Players:GetChildren()
    cloned.Parent = player.Backpack
    cloned.Parent = player.StarterGear
print("cool")
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted 
end

1 answer

Log in to vote
0
Answered by
memguy 161
4 years ago

:GetChildren() returns an array of all children of an object. Basically, the player variable was not the player but all of them.

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local players = game.Players:GetPlayers()
for i=1,#players do
if players[i].UserId == receiptInfo.PlayerId then
    local RS = game:GetService("ReplicatedStorage")
    local item = RS:WaitForChild("Popcorn")
    local cloned = item:Clone()
    local player = players[i]
    cloned.Parent = player.Backpack
    cloned.Parent = player.StarterGear
print("cool")
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted 
end
0
unfortunately it still does not work Zeppelin0330 38 — 4y
Ad

Answer this question