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])
Added services to the top of the screen so that way it is easier to access things
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)
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)