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.Character:FindFirstChild(tool.Name) then
return
end
if player.Backpack:FindFirstChild(tool.Name) then
return
end
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')
frame.Visible = false
local function shopMenu(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player then
player.PlayerGui.ScreenGui.Shop.Visible = true
player.Character.Humanoid.WalkSpeed = 0
end
end
local function closeMenu()
local player = game.Players.LocalPlayer
player.PlayerGui.ScreenGui.Shop.Visible = false
player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)
player.Character.Humanoid.WalkSpeed = 16
end
local function buyTool1()
local tool = ReplicatedStorage.ShopItems['Name of Tool1']
remoteEvent:FireServer(tool)
end
local function buyTool2()
local tool = ReplicatedStorage.ShopItems['Name of Tool2']
remoteEvent:FireServer(tool)
end
local function buyTool3()
local tool = ReplicatedStorage.ShopItems['Name of Tool3']
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)
FAQ and Solutions
My words are a different color
That is okay. Unlined words indicate errors, but if they are just a different color that's fine.
The Frame is open when I run the game
Likely errors:
The open part is not named correctly
local open = game.Workspace.openPart
This line defines the open part. If you did not name the part that the player steps on openPart then change the name in the explorer menu.
The close part is not named correctly
local close = game.Workspace.closePart
This line defines the close part. If you did not name the part the player goes to when the frame closes closePart then change the name in the explorer menu.
The Gui objects are not named correctly
local closeButton = frame.closeButton
local buy_1 = frame.buy1
local buy_2 = frame.buy2
local buy_3 = frame.buy3
The gui objects inside the frame must match the names used in the script. Make sure your close button is named closeButton. Make sure your buy buttons are name buy1, buy2, and buy3.
The remote event was not added or named incorrectly
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')
Make sure you add a remote event toReplicatedStorage and rename it to BuyTool.
My error is not here
Use the output to identify the error and post it in chat
The Frame is open when I run the game
local function closeMenu()
local player = game.Players.LocalPlayer
player.PlayerGui.ScreenGui.Shop.Visible = false
player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)
player.Character.Humanoid.WalkSpeed = 16
end
closeButton.MouseButton1Click:Connect(closeMenu)
This part closes the frame. Check to make sure there are no errors. Also make sure you have renamed the Frame inside the ScreenGui to Shop.
I can't add the images
You must publish your game before you can add images.
I can't find AutoScale Lite
Plugins can now be found in the toolbox on Studio. Select Plugins from the dropdown and search for AutoScale Lite.
I want to use different items in my shop
To use a different tool make sure you add the tool to the ShopItems folder we added to ReplicatedStorage.
local tool = ReplicatedStorage.ShopItems['Name of Tool1']
In each buyTool function there is a line that looks like the one above. Replace "Name of Tool" with the name of the tool you want to use. Make sure you keep the name inside quotation marks. The name must match exactly.
The leaderstats don't show up
Check the leaderstats script above to make sure you have no errors. Make sure you put the code in a Script not a LocalScript and that you put the Script in ServerScriptService not ServerStorage.
Price is not a valid member of Tool
If you get this error that means you did not add the IntValue to the tool and rename it to Price.
When I click the buy button I don't get the tool
Start by checking the output to see if you are getting any error messages.
local function buyTool1()
local tool = ReplicatedStorage.ShopItems['Name of Tool1']
remoteEvent:FireServer(tool)
end
local function buyTool2()
local tool = ReplicatedStorage.ShopItems['Name of Tool2']
remoteEvent:FireServer(tool)
end
local function buyTool3()
local tool = ReplicatedStorage.ShopItems['Name of Tool3']
remoteEvent:FireServer(tool)
end
buy_1.MouseButton1Click:Connect(buyTool1)
buy_2.MouseButton1Click:Connect(buyTool2)
buy_3.MouseButton1Click:Connect(buyTool3)
This is the sections of code from the LocalScript that deal with buying tools. Make sure there are no errors here. Sometimes you may get an extra ( ) inside Connect ( ) like this buy_1.MouseButton1Click:Connect(buyTool1 ( ) ). Delete the extra ( ).
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')
local function buyTool(player, tool)
if player.Character:FindFirstChild(tool.Name) then
return
end
if player.Backpack:FindFirstChild(tool.Name) then
return
end
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)
This section of code above is the final part in getting the tool to the player.
if player.Character:FindFirstChild(tool.Name) then
return
end
if player.Backpack:FindFirstChild(tool.Name) then
return
end
This part checks to see if the player already has the tool in their hand or in their backpack.
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
This section starts by checking to see if the player has enough Money to buy the tool. If you did not add a IntValue inside the tool in ReplicatedStorage and rename it to Price this will cause an error in the first line.
The two giveTool sections copies the tool from the ShopItems folder in ReplicatedStorage and puts it in the players Backpack and in their StarterGear so they have it after death.
Make sure this is a Script inside ServerScriptService!