Script help(I’m a noob)

** – Create a ScreenGui instance
local gui =“ScreenGui”)
gui.Parent = game.Players.LocalPlayer.PlayerGui

– Create a TextButton instance
local button =“TextButton”)
button.Text = “Buy Item”
button.Size =, 200, 0, 50)
button.Position =, -100, 0.5, -25)
button.Parent = gui

– Define the function that will be called when the button is clicked
local function onButtonClicked()
– TODO: Add code to buy the item here

– Connect the function to the button’s Click event

The script is above. I want player to be able to buy avatar items

Here are the models to the models I already have: This is the shop model link: (4) Hat Choosing System - Roblox
This is the money model: Ungroup in ServerScript - Roblox

1 Like

Why not just make a Gui in starter Gui and disable it? When the function should be called just enable the Gui.

By doing a buying system, I had some problems with the subtraction part with the money and I fixed it by subtracting on all clients.

How?? Bro I’m trash please give further instruct

The dev forum says to not write whole scripts for people, I prefer giving help than giving the direct answer. But since you insist then to enable a Gui, use in the function TheGui.Enabled = true or false depending on if you want it enabled or not

here you go, i guess…

(fixed the code for you)

-- Create a ScreenGui instance
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local gui ="ScreenGui", LocalPlayer.PlayerGui)

-- Create a TextButton instance
local button ="TextButton", gui)
button.Text = "Buy Item"
button.Size = UDim2.fromScale(200, 50)
button.Position =, -100, 0.5, -25)

-- Connect the Event
    MarketplaceService:PromptPurchase(LocalPlayer, 123456) -- replace 123456 with the asset Id you want

But I want player to lose coins tho

what is the coins name and it’s full name?, so I will fix it for you…

Here is the money script Ungroup in ServerScript - Roblox. Let me know if the sales are privet tho

You should make a ScreenGui normally, instead of creating it with a script. The local script in the gui can then handle the button.

The coins full name is Coin for the money script.