Script help(I’m a noob)

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

– Create a TextButton instance
local button = Instance.new(“TextButton”)
button.Text = “Buy Item”
button.Size = UDim2.new(0, 200, 0, 50)
button.Position = UDim2.new(0.5, -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
end

– Connect the function to the button’s Click event
button.MouseButton1Click:Connect(onButtonClicked)**

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 = Instance.new("ScreenGui", LocalPlayer.PlayerGui)

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

-- Connect the Event
button.MouseButton1Click:Connect(function()
    MarketplaceService:PromptPurchase(LocalPlayer, 123456) -- replace 123456 with the asset Id you want
end)

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.