Forja

Roblox shop GUI script

A shop screen that sells tools for coins. The prices live on the server and the server does the sum, so a cheater can't buy anything for free.

Where it goes

  1. 1You need a Coins stat: the leaderboard script makes one. Put each Tool you're selling in ServerStorage.
  2. 2In ServerScriptService, add a Script with the first code, and change PRICES to your tools' exact names and prices.
  3. 3In StarterPlayer, then StarterPlayerScripts, add a LocalScript with the second code, and press Play.
ShopServer · a Script in ServerScriptService
-- From forja.us/tools/roblox-scripts/shop-gui-- Sells tools for coins. Prices are here, on the server, so players can't change them.local Players = game:GetService("Players")local ReplicatedStorage = game:GetService("ReplicatedStorage")local ServerStorage = game:GetService("ServerStorage")local PRICES = {	Sword = 100,	Flashlight = 50,}local shop = Instance.new("RemoteFunction")shop.Name = "Shop"shop.Parent = ReplicatedStoragelocal function ownsAlready(player, itemName)	local backpack = player:FindFirstChildOfClass("Backpack")	local character = player.Character	return (backpack and backpack:FindFirstChild(itemName)) or (character and character:FindFirstChild(itemName))endshop.OnServerInvoke = function(player, itemName)	if itemName == nil then		return PRICES	end	local price = PRICES[itemName]	local tool = price and ServerStorage:FindFirstChild(itemName)	local leaderstats = player:FindFirstChild("leaderstats")	local coins = leaderstats and leaderstats:FindFirstChild("Coins")	local backpack = player:FindFirstChildOfClass("Backpack")	if not tool or not coins or not backpack then		return "That isn't for sale."	end	if ownsAlready(player, itemName) then		return "You already have it."	end	if coins.Value < price then		return "Not enough coins."	end	coins.Value -= price	tool:Clone().Parent = backpack	return "Bought!"end
ShopScreen · a LocalScript in StarterPlayerScripts
-- From forja.us/tools/roblox-scripts/shop-gui-- Builds the shop's buttons from the prices the server sends.local Players = game:GetService("Players")local ReplicatedStorage = game:GetService("ReplicatedStorage")local shop = ReplicatedStorage:WaitForChild("Shop")local screen = Instance.new("ScreenGui")screen.Name = "Shop"screen.ResetOnSpawn = falsescreen.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")local list = Instance.new("Frame")list.Size = UDim2.fromOffset(220, 0)list.Position = UDim2.new(0, 16, 0.5, 0)list.AnchorPoint = Vector2.new(0, 0.5)list.AutomaticSize = Enum.AutomaticSize.Ylist.BackgroundTransparency = 1list.Parent = screenlocal layout = Instance.new("UIListLayout")layout.Padding = UDim.new(0, 6)layout.SortOrder = Enum.SortOrder.Namelayout.Parent = listfor itemName, price in shop:InvokeServer() do	local button = Instance.new("TextButton")	button.Name = itemName	button.Size = UDim2.new(1, 0, 0, 40)	button.Font = Enum.Font.GothamMedium	button.TextSize = 16	button.Text = itemName .. ": " .. price .. " coins"	button.Parent = list	button.Activated:Connect(function()		button.Text = shop:InvokeServer(itemName)		task.wait(1.5)		button.Text = itemName .. ": " .. price .. " coins"	end)end

How it works

  • The client only asks to buy a name. The server looks up the price and does the sum, so a cheater can't send their own price.
  • A RemoteFunction sends an answer back, which is what shows on the button.
  • The buttons are made from what the server sends, so a new line in PRICES adds a new button.

Make it yours

Keep what they buy
This lasts until they reset. Add a copy to the player's StarterGear as well, and it comes back after a respawn.
Make it look like your game
The look is all in the second script. Or start from a UI kit.
Want something more? The script generator can write it: “A shop screen where players buy tools with coins, with a picture and a price for each”

Maps to try it on: simulator and tycoon maps

Start from a finished map, and your scripts have a game to run in.

More free Roblox scripts