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

why is promptpurchase prompting everyone in game? [SOLVED]

Asked by 9 years ago

i am using promptproduct purchase for developer products i'm selling and promptpurchase for me gamepasses. i'm getting complaints from players about being prompted to purchase my game passes, but i don't have any auto-prompts running, only clickdetectors to prompt whoever clicks it. i've been selling developer products for awhile and haven't had complaints about being prompted, but i just added gamepasses to be purchased ingame and now i'm getting the complaints about being prompted to buy a pass, so i assume it's only doing this when a player clicks to purchase a gamepass, and not a developer product. the only difference between the two one uses promptproductpurchase and the other uses promptpurchase. i have the prompt script in a serverscript located inside player gui. this is what i'm doing, what dshould i do differently?

buyButton.MouseClick:connect(function(player)
    game:GetService("MarketplaceService"):PromptPurchase(player, productId)
end)

EDIT

here's the test place with a copy of the scripts.

I've moved the prompt script to a local script inside of playergui

here's my code

--this is the localscript



local assetid
local player


local function showinfoproduct()
local store = script.Parent.store
local image = store.frame.frame.Thumbnail
local name = store.frame.frame.ItemName
local price = store.frame.frame.CurrencyAmount
local price2 = store.frame.frame.CurrencyAmount2
local disc = store.frame.description
local asset = game:GetService("MarketplaceService"):GetProductInfo(assetid, Enum.InfoType.Product)
price.Text = asset.PriceInRobux
price2.Text = asset.PriceInTickets
disc.Text = asset.Description
name.Text = asset.Name
store.frame.Visible = true
image.Image = "http://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=" .. assetid
end


local buybutton = workspace.Part.ClickDetector

local buybutton1 = workspace.Part1.ClickDetector

local developerproductid = 23348913




buybutton.MouseClick:connect(function(player)
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, developerproductid)
end)



buybutton1.MouseClick:connect(function(player)
    assetid = developerproductid
    showinfoproduct()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, developerproductid)
end)




shirtbutton.MouseClick:connect(function(player)
assetid = shirtid
showinfoasset()
game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, shirtid)
 end)



shirtbutton1.MouseClick:connect(function(player)

game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, shirtid)
 end)





with this above, in a local script it is prompting everyone not just the player who clicks. and it shows the description gui to all players

but if i move it to a serverscript it only prompts the player who clicked. but it opens the description gui on all players.

--this is the serverscript




local assetid
local player



local function showinfoasset()
local store = script.Parent.store1
local image = store.frame.frame.Thumbnail
local name = store.frame.frame.ItemName
local price = store.frame.frame.CurrencyAmount
local price2 = store.frame.frame.CurrencyAmount2
local disc = store.frame.description
local asset = game:GetService("MarketplaceService"):GetProductInfo(assetid)
price.Text = asset.PriceInRobux
price2.Text = asset.PriceInTickets
disc.Text = asset.Description
name.Text = asset.Name
store.frame.Visible = true
image.Image = "http://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=" .. assetid
end



local function showinfoproduct()
local store = script.Parent.store1
local image = store.frame.frame.Thumbnail
local name = store.frame.frame.ItemName
local price = store.frame.frame.CurrencyAmount
local price2 = store.frame.frame.CurrencyAmount2
local disc = store.frame.description
local asset = game:GetService("MarketplaceService"):GetProductInfo(assetid, Enum.InfoType.Product)
price.Text = asset.PriceInRobux
price2.Text = asset.PriceInTickets
disc.Text = asset.Description
name.Text = asset.Name
store.frame.Visible = true
image.Image = "http://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=" .. assetid
end



local buybutton= workspace.Part.ClickDetector
local buybutton1= workspace.Part1.ClickDetector
local developerproductid = 23348913





buybutton.MouseClick:connect(function(player)
    game:GetService("MarketplaceService"):PromptProductPurchase(player, developerproductid)
end)



buybutton1.MouseClick:connect(function(player)
    assetid = developerproductid
    showinfoproduct()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, developerproductid)
end)




local shirtbutton = game.Workspace.purple.shirtbuy.ClickDetector
local shirtbutton1 = game.Workspace.purple1.shirtbuy.ClickDetector

local shirtid  = 235468209--purple





shirtbutton.MouseClick:connect(function(player)
assetid = shirtid
showinfoasset()
game:GetService("MarketplaceService"):PromptPurchase(player, shirtid)
 end)



shirtbutton1.MouseClick:connect(function(player)

game:GetService("MarketplaceService"):PromptPurchase(player, shirtid)
 end)

ok fixed now. I've pasted the corrected script below.


local assetid local player local function showinfoasset() local store = game.Players:FindFirstChild(player.Name).PlayerGui.store local image = store.frame.frame.Thumbnail local name = store.frame.frame.ItemName local price = store.frame.frame.CurrencyAmount local price2 = store.frame.frame.CurrencyAmount2 local disc = store.frame.description local asset = game:GetService("MarketplaceService"):GetProductInfo(assetid) price.Text = asset.PriceInRobux price2.Text = asset.PriceInTickets disc.Text = asset.Description name.Text = asset.Name store.frame.Visible = true image.Image = "http://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=" .. assetid end local function showinfoproduct() local store = game.Players:FindFirstChild(player.Name).PlayerGui.store local image = store.frame.frame.Thumbnail local name = store.frame.frame.ItemName local price = store.frame.frame.CurrencyAmount local price2 = store.frame.frame.CurrencyAmount2 local disc = store.frame.description local asset = game:GetService("MarketplaceService"):GetProductInfo(assetid, Enum.InfoType.Product) price.Text = asset.PriceInRobux price2.Text = asset.PriceInTickets disc.Text = asset.Description name.Text = asset.Name store.frame.Visible = true image.Image = "http://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=" .. assetid end local dvbutton = workspace.Part.ClickDetector local dvbutton1 = workspace.Part1.ClickDetector local developerproductid = 23348913 dvbutton1.MouseClick:connect(function(clicker) print(clicker) player = clicker game:GetService("MarketplaceService"):PromptProductPurchase(clicker, developerproductid) end) dvbutton.MouseClick:connect(function(clicker) print(clicker) player = clicker assetid = developerproductid showinfoproduct() game:GetService("MarketplaceService"):PromptProductPurchase(clicker, developerproductid) end)
0
There's absolutely no reason for this at all, if the given code is the only code that controls the prompting. Do you have skype? Perhaps I can help you better from there. Goulstem 8144 — 9y

1 answer

Log in to vote
1
Answered by
DrJonJ 110
9 years ago

Your problem with the ServerScript one is that is runs all of them together. Meaning that when player A clicks, it triggers the function for player B. This is bad practice, and the reason it shows everyone the info UI is because you don't tell it what player to show it to.

I will edit this post later with a fix if you still can't figure it out.

Tip: add a parameter for the player object instead of using 'script.Parent' and you'll only need one script in ServerScriptService.

Maybe I should do a blog post on efficiency...

0
thank you. i was just told that MouseClick fires for all players. i didn't know this. i'm working on a fix right now. I thought it was best practice to get the event from the client with one clientside script and then process the event with another serverside script . johnnygadget 50 — 9y
0
While it does fire for all players, you can still use it. Just make sure that you check if the player is the same one returned from the function as your first line. DrJonJ 110 — 9y
Ad

Answer this question