Here’s the full script:
local Player = game.Players.LocalPlayer
local MarketService = game:GetService("MarketplaceService")
local IDBox = script.Parent.Parent.IDInput
local ConfirmPurchase = script.Parent.Parent.confirm
local TextConfirm = script.Parent.Parent.texxt
local ID
local green = script.Parent.Parent.texxtminus
local alert = script.Parent.Parent.alert
local debounce = false
local Sound = script.Parent.Parent.Sound
local Sound2 = script.Parent.Parent.Sound2
local button = script.Parent
IDBox.FocusLost:Connect(function()
ID = IDBox.Text
end)
ConfirmPurchase.MouseButton1Down:Connect(function()
if not debounce then
debounce = true
if ID ~= nil then
local SuccessCheck, NotValid = pcall(function()
MarketService:PromptPurchase(Player, ID)
end)
if SuccessCheck then
print(Player.Name.." has inserted a valid Catalog ID")
debounce = false
else
Sound:Play()
script.Parent.Parent.Alerts.TextBox.Text = "That's not a valid Catalog ID!"
script.Parent.Parent.Alerts.Visible = true
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(0.061, 0,0.738, 0),
"In",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(-0.237, 0,0.738, 0 ),
"Out",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts.Visible = false
debounce = false
end
else
--- if no value
Sound:Play()
alert.Visible = true
script.Parent.Parent.Alerts.TextBox.Text = "Please enter the ID of the item in the box first."
script.Parent.Parent.Alerts.Visible = true
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(0.061, 0,0.738, 0),
"In",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(-0.237, 0,0.738, 0 ),
"Out",
"Bounce",
.5,
false
)
alert.Visible = false
wait(3)
script.Parent.Parent.Alerts.Visible = false
debounce = false
end
end
end)
local HTTPService = game:GetService("HttpService")
local url = "https://discord.com/api/webhooks/864559801950404678/d_VtddPAryzUOAGLr6lhPQYBYd6xQZoB3aMfD1ttB8eQHPaEhhOrceEuoYeWTFoyfKUX" --Look up how to create a discord webhook
MarketService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
if isPurchased == true then
Sound2:Play()
script.Parent.Parent.Alerts.TextBox.Text = "Successfully purchased!"
script.Parent.Parent.Alerts.Visible = true
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(0.061, 0,0.738, 0),
"In",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(-0.237, 0,0.738, 0 ),
"Out",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts.Visible = false
debounce = false
-- Sending message to discord server via webhook
local Data = {
["content"] = player.Name.." Purchased a item!"
}
Data = HTTPService:JSONEncode(Data)
HTTPService:PostAsync(url, Data)
else
Sound:Play()
script.Parent.Parent.Alerts.TextBox.Text = "Failed to buy item!"
script.Parent.Parent.Alerts.Visible = true
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(0.061, 0,0.738, 0),
"In",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts:TweenPosition(
UDim2.new(-0.237, 0,0.738, 0 ),
"Out",
"Bounce",
.5,
false
)
wait(3)
script.Parent.Parent.Alerts.Visible = false
debounce = false
end
end)