Ahh okay because like I am trying to achieve a GUI shop script that gives a player a tool, on top of that I’d have to get the money system working so knowing this would be helpful
Hello, There are tons of tutorials but I will try to explain as simple as I can. So, you’ll typically use RemoteEvents and RemoteFunctions. These allow you to send messages and data between the server and client securely.
Here’s a basic breakdown:
RemoteEvents
Used for one-way communication.
Example: Telling the server that a client clicked a button.
RemoteFunctions
Used for two-way communication.
Example: Asking the server how much money a player has and waiting for a response.
Let’s say you have a GUI on the client where players can buy a tool. When a player clicks the “Buy” button, you want to:
Get the player’s money.
Give the player the tool if they have enough money.
Server: (Note this is just an example, you should change some stuff in order to work)
Create a RemoteEvent in ReplicatedStorage named “BuyToolEvent”.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local BuyToolEvent = ReplicatedStorage:WaitForChild("BuyToolEvent")
BuyToolEvent.OnServerEvent:Connect(function(player, toolName)
local playerMoney = player:WaitForChild("leaderstats"):WaitForChild("Money").Value
local toolCost = 100 -- This can be dynamic based on the tool
if playerMoney >= toolCost then
player:WaitForChild("leaderstats"):WaitForChild("Money").Value = playerMoney - toolCost
local tool = game.ServerStorage:FindFirstChild(toolName):Clone()
tool.Parent = player.Backpack
else
-- Player doesn't have enough money
end
end)
Client:
When the player clicks the “Buy” button:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local BuyToolEvent = ReplicatedStorage:WaitForChild("BuyToolEvent")
local buyButton = script.Parent -- Assuming this script is a child of the button
buyButton.MouseButton1Click:Connect(function()
BuyToolEvent:FireServer("ToolName") -- Replace "ToolName" with the name of the tool the player is trying to buy
end)
If you need a response from the server (e.g., to know if the purchase was successful), you’d use a RemoteFunction instead of a RemoteEvent. The client would call the function, the server would process the request, and then the server would return a response to the client. I think this will help you!