Shop GUI

Video Tutorial

Final Scripts

Notes:

Add a RemoteEvent to Replicated Storage

Add tools that are being sold under Replicated Storage

Each tool should have have an IntValue renamed to Price

Set the value of that IntValue to what you want the price of the tool to be

If you name parts or tools other names make sure to update the appropriate lines in the script as well

Buy Script (ServerScriptService)

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')


local function buyTool(player, tool)

if player.leaderstats.Money.Value >= tool.Price.Value then

player.leaderstats.Money.Value = player.leaderstats.Money.Value - tool.Price.Value

local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()

giveTool.Parent = player.Backpack

local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()

giveTool.Parent = player.StarterGear

end

end



remoteEvent.OnServerEvent:Connect(buyTool)


Leaderstats (ServerScriptService)

local function onPlayerJoin(player)

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player


local money = Instance.new("IntValue")

money.Name = "Money"

money.Value = 5000

money.Parent = leaderstats

end


game.Players.PlayerAdded:Connect(onPlayerJoin)


LocalScript Under Frame (Final)

local open = game.Workspace.openPart

local close = game.Workspace.closePart

local frame = script.Parent

local closeButton = frame.closeButton

local buy_1 = frame.buy1

local buy_2 = frame.buy2

local buy_3 = frame.buy3


local ReplicatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')


local LPlayer = game.Players.LocalPlayer --New variable for local player


frame.Visible = false


local function shopMenu(otherPart)

local player = game.Players:FindFirstChild(otherPart.Parent.Name)

if player == LPlayer then --New fixes an error message

player.PlayerGui.ScreenGui.Shop.Visible = true

player.Character.Humanoid.WalkSpeed = 0

end

end


local function closeMenu() --Updated to use LPlayer

LPlayer.PlayerGui.ScreenGui.Shop.Visible = false

LPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)

LPlayer.Character.Humanoid.WalkSpeed = 16

end


local function buyTool1()

local tool = ReplicatedStorage.ShopItems.TommyGun

remoteEvent:FireServer(tool)

end


local function buyTool2()

local tool = ReplicatedStorage.ShopItems.ClassicSword

remoteEvent:FireServer(tool)

end


local function buyTool3()

local tool = ReplicatedStorage.ShopItems.hyper

remoteEvent:FireServer(tool)

end


open.Touched:Connect(shopMenu)

closeButton.MouseButton1Click:Connect(closeMenu)

buy_1.MouseButton1Click:Connect(buyTool1)

buy_2.MouseButton1Click:Connect(buyTool2)

buy_3.MouseButton1Click:Connect(buyTool3)