Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I get this script to allow myself buy items from the catalog by typing in the ID?

Hello! I am Glassphyte, and I seem to be in some trouble and wish for help. I've watched a certain ROBLOX video and what happened in it peaked my interest. I see the user has made a small.. script which allows him to buy a catalog item from his game, by just entering the ID and pressing enter! I attempted to make something like that myself.. but it didn't succeed. I made the screengui somewhat like his, but added a textbox and textbutton. So instead of pressing enter, I press the 'Confirm' button, that's to the side of the textbox. Like I said though, I had no luck.

Can anyone try to help me out with this? Thank you.

Here is the link to his video.

https://www.youtube.com/watch?v=zaB1iEDrWAU

Here is what I've made so far of the script.

-- Script for In-Game Selling

local box = script.Parent.Parent:WaitForChild("TextBox")
local button = script.Parent

local ItemID = ("TextBox")

script.Parent.ClickDetector.MouseClick:connect(function(player)
	Game:GetService("MarketplaceService"):PromptPurchase(player, ItemID)
end)

-- Made by Glassphyte

2 answers

1.If FilteringEnabled is on, do NOT use a script, use a LocalScript.
2.The class "TextButton" does not have a "MouseClick" function, change it to "MouseButton1Click".
3. "local ItemID = ("TextBox")" is not a thing. Instead, use "local ItemID = box.Text"
4.ClickDetectors don't do anything when in a Gui, remove it.
5. Much More.
Here is my answer:

local TextBox = script.Parent.Parent.TextBox --Finds the TextBox

local ItemID = TextBox.Text --Gets the string entered.

script.Parent.MouseButton1Down:Connect(function(Player) --Make sure the script's parent is a TextButton
    Game:GetService("MarketplaceService"):PromptPurchase(Player, ItemID)
end)

-- Totally not made by Glassphyte. It is better.
local player = game.Players.LocalPlayer
-- Lowercase 'g'ame
local MarketplaceService = game:GetService("MarketplaceService")
local box = script.Parent.Parent:WaitForChild("TextBox")
local button = script.Parent

-- ClickDetectors go in Parts, not GUI's.
button.MouseButton1Down:connect(function()
	-- Match all numbers in your input, else default to 12345
	local txt = box.Text:match("%d+") or 12345
    MarketplaceService:PromptPurchase(player, txt)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.