So I have this script (not local) which is inside a TextButton (when clicked, the purchase prompt for the developer product should appear):
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
local link = game:GetService("MarketplaceService")
deb = 0
script.Parent.MouseButton1Click:connect(function()
local marketId = 1301207378 -- Developer Product
link:PromptProductPurchase(plr,marketId)
link.ProcessReceipt = function(receiptInfo)
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
if deb == 0 then
deb = 1
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 250 -- Amount added after purchase
wait(1)
deb = 0
end
end
end
end)
But for some reason when I click, nothing happens or appears, instead I get this error:
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent.Parent.Parent)
if the script.Parent.Parent.Parent.Parent.Parent.Parent was the player’s character.
also why ru using “MouseButton1Click” event in a script that wouldn’t work.
you could fire a remote event to the server
local Remote = game.ReplicatedStorage.YourRemote
-- LocalScript
script.Parent.MouseButton1Click:connect(function()
Remote:FireServer()
end)
-- ServerScript
local Remote = game.ReplicatedStorage.YourRemote
Remote.OnServerEvent:Connect(function(plr)
local marketId = 1301207378 -- Developer Product
link:PromptProductPurchase(plr,marketId)
link.ProcessReceipt = function(receiptInfo)
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
if deb == 0 then
deb = 1
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 250 -- Amount added after purchase
wait(1)
deb = 0
end
end
end
end)
If you want to use server scripts, you could use click detectors with .MouseClick instead because it has a player argument. You could also use local scripts and use local player to detect who clicked on the button.