Finish script help

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

Here’s the cash script I have: – 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)

I’m not sure how to do the —TODO

This was a fun one to fix:

I did not have much time to fix so it was kind of rushed. But before I give you the code for it, I want to give you some friendly reminders on how to code (from what I like) (These are optional [Just organised better])

  1. Added services to the top of the screen so that way it is easier to access things
  2. If your ever transfering data from the client to the server, use remote events!
-->> Services <<--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-->> Remotes / Modules <<--
local PurchaseRemote = ReplicatedStorage.PurchaseRemote

-->> GUI Input <<--

local GUI = Instance.new("ScreenGui", Players.LocalPlayer.PlayerGui) -- Makes a GUI go inside of the player's Gui
GUI.Name = "BuyItem" -- Just the name of the GUI (You can change it or remove it.. just make sure the game knows what to do!)

local NewButton = Instance.new("TextButton", GUI)
NewButton.Text = "Purchase Item"
NewButton.Size = UDim2.new(0,200,0,50)
NewButton.Position = UDim2.new(0.5,-100,0.5,-25)

-->> Functions <<--

local function  onButtonClicked()
	PurchaseRemote:FireServer() -- Add any data you want to in here lol
end

-->> Interacted <<--

NewButton.MouseButton1Click:Connect(onButtonClicked)

So, how to i make it so the player loses in game cash??

Sorry for the late reply, but i’m assuming you mean when they purchase something.

local function  onButtonClicked()
	PurchaseRemote:FireServer(100) -- In here is the cost for it (You can change it or rewrite it to work for a specific item! This is just a basic)
end

Server Script:

game.ReplicatedStorage.PurchaseRemote.OnServerEvent:Connect(function(player, cost)
	local leaderstats = player.leaderstats -- This is just a quick definition, can be changed to whatever you want lol.
	
	leaderstats.Cash.Value -= cost
end)