Hello!
I have been struggling for so long now. Please help me
I have created a small purchasing stand for my game. I want it to prompt purchase one of my developer products.
How would I go about this? I have tried free models, Roblox Developer website, youtube videos, and it still never seems to work.
You canât use game.Players.LocalPlayer inside of scripts, and unfortunately, script.Parent.MouseButton1Click:Connect(function(h) doesnât register who clicked it. Iâd recommend you to create a new part, insert a ClickDetector to it, and scale it down to an appropriate size that fits as a replacement. After, insert a script into the ClickDetector, and use the code:
--[ Variables
local cd = script.Parent
local mps = game:GetService("MarketplaceService")
--[ Setup
cd.MouseClick:Connect(function(plr)
mps:PromptPurchase(plr, 000)
end)
Ok, you have to first put a click detector inside your button that you want the player to click.
Then you need to use marketplaceservice to prompt a product purchase.
Put a script inside the part that has the clickdetector.
local MarketPlaceService = game:GetService("MarketPlaceService") -- This service is used for prompting purchases or checking if a player has purchased items.
Script.Parent.ClickDetector.MouseClick:Connect(function(player) -- Puts a player parameter in this event so that we can access the player who clicked
MarketPlaceService:PromptProductPurchase(player.UserId, YourDevProductID) -- This prompts a purchase for the player who clicks,
end)
Just switch the âScriptâ to a âLocalScriptâ.
The code is fine, even though I wouldnât say itâs an efficient way to do this, but it works fine.
Edit: I just realized SurfaceGui is not under the PlayerGui, so what I would do is put the LocalScript under the Player directory and change the hierarchy in the code to match the new position of the TextButton.
Forgot to mention this: you should move the SurfaceGui under the PlayerGui as well, you canât interact with it otherwise.
Insert a Click Detector, and use the built-in function MouseClick, which is used for Click Detectors, also this script will not work unless you use a Local Script, because you canât access the âLocal Playerâ from a regular Script.
Forgot to mention this, but you need to put the Click Detector inside the text button.