Hi!
I’m making a Purchase System for an Obby. I will try my best to explain this!
When someone clicks the Buy! button in the shop, to buy a DevProduct, this LocalScript executes (it is inside the button), and it works:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local devproductPromptEvent = ReplicatedStorage:WaitForChild("DevProductPromptEvent")
local button = script.Parent
local loading = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("Loading").Frame
button.MouseButton1Down:Connect(function()
devproductPromptEvent:FireServer(*DevProductHere*)
loading.Visible = true
print("DevProduct Prompt Event Fired!")
end)
That Remote Event then fires this normal script that is inside ServerScriptService and everything works too:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local gamepassPromptEvent = ReplicatedStorage.GamepassPromptEvent --For gamepasses
local devproductPromptEvent = ReplicatedStorage.DevProductPromptEvent --For devproducts
--This only executes if the last script is selling a gamepass and not a devproduct
gamepassPromptEvent.OnServerEvent:Connect(function(player, id)
MarketplaceService:PromptGamePassPurchase(player, id)
print("Gamepass Prompted!")
end)
--End
--This Remote Event is the one that the last script fired
devproductPromptEvent.OnServerEvent:Connect(function(player, id)
MarketplaceService:PromptProductPurchase(player, id)
print("DevProduct Prompted!")
end)
Then, that DevProductPromptEvent fires this script in line 17 because the player was trying to purchase a DevProduct (not a Gamepass) and it goes to line 22 because the player canceled the purchase, but then the Remote Event in that line isn’t fired…
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local purchaseFinishedEvent = ReplicatedStorage:WaitForChild("PurchaseFinishedEvent")
local purchaseUnfinishedEvent = ReplicatedStorage:WaitForChild("PurchaseUnfinishedEvent")
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, assetId, isPurchased)
if isPurchased then
purchaseFinishedEvent:FireClient(player) --*This doesn't work!!!*
print(player.Name .. " bought an item with AssetID: " .. assetId)
else
purchaseUnfinishedEvent:FireClient(player) --*This doesn't work!!!*
print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, assetId, isPurchased) --Goes to here because the player was buying a DevProduct
if isPurchased then
purchaseFinishedEvent:FireClient(player) --*This doesn't work!!!*
print(player.Name .. " bought an item with AssetID: " .. assetId)
else
purchaseUnfinishedEvent:FireClient(player) --*Tries to fire this Remote Event and it doesn't work!!!*
print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
end
end)
Everything in this script works, except the part that then tries to fire the LocalScript that is in StarterPlayerScripts because of this error in line 22, but this will also happen in line 9, 12 and 19:
I know that this is very confusing, but can someone help me fix this issue, editing the script?
Thanks! <3