(Sorry for bad English)
I have create a Part and, inside the Part, i have insert this script:
local productId = 662920300 local player = game.Players.LocalPlayer function Shop(hit) game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end script.Parent.Touched:connect(Shop)
But i have this error in the Output ->
MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type nil
How i can fix this problem? (When people touch the Part, the PromptProductPurchase is triggered)
And after this... i need to remove this part after the purchase is complete from the world (or just transfer the Part in the ReplicatedStorage)
Your script is a server script, and that means you can't use game.Players.LocalPlayer
. That trick only works in LocalScripts. To find a player in the server script you need to use GetPlayerFromCharacter
. I also made some more adjustments for You, because I am in good mood.
local MarketPlaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local promptedPlayers = {} --remember players who have been prompted local productId = 662920300 function Shop(hit) if hit.Parent:FindFirstChild("HumanoidRootPart") then --only prompt players player = Players:GetPlayerFromCharacter(hit.Parent) if not promptedPlayers[player] then promptedPlayers[player] = true MarketplaceService:PromptProductPurchase(player, productId) end end end script.Parent.Touched:connect(Shop)
Have a nice scripting session.