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
- 1You need a Coins stat: the leaderboard script makes one. Put each Tool you're selling in ServerStorage.
- 2In ServerScriptService, add a Script with the first code, and change
PRICESto your tools' exact names and prices. - 3In StarterPlayer, then StarterPlayerScripts, add a LocalScript with the second code, and press Play.
-- 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-- 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)endHow 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
RemoteFunctionsends an answer back, which is what shows on the button. - The buttons are made from what the server sends, so a new line in
PRICESadds a new button.
Make it yours
- Keep what they buy
- This lasts until they reset. Add a copy to the player's
StarterGearas 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.
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
Roblox kill brick scriptRoblox leaderboard scriptRoblox save data scriptRoblox sprint scriptRoblox double jump scriptRoblox teleport scriptRoblox obby checkpoint scriptRoblox coin pickup scriptRoblox day and night cycle scriptRoblox game pass scriptRoblox developer product scriptRoblox door scriptRoblox tool giver scriptRoblox round system scriptRoblox background music scriptRoblox speed pad scriptRoblox jump pad scriptRoblox VIP door scriptRoblox daily reward scriptRoblox NPC dialogue scriptRoblox pet follow scriptRoblox gun scriptRoblox admin commands scriptRoblox tycoon dropper script

