✓ Accepted answer
###For that you would use a RemoteEvent. According to Wiki, "The first difference is that RemoteFunctions are designed for two way communication, while RemoteEvents are designed for one way. A RemoteFunction sends a request and then waits for a response, while RemoteEvents just send a request." With that in mind, here is a little example on how to use a RemoteEvent and RemoteFunction.
#RemoteEvent
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createExplosion = Instance.new("RemoteEvent")
createExplosion.Name = "CreateExplosion"
createExplosion.Parent = ReplicatedStorage
createExplosion.OnServerEvent:Connect(function(player, otherPlayer)
if Players:FindFirstChild(otherPlayer) then
local plr = Players[otherPlayer]
local exp = Instance.new("Explosion")
exp.Position = plr.Character.Head.Position
exp.Paarent = workspace
end
end)
###From the client:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createExplosion = ReplicatedStorage:WaitForChild("CreateExplosion")
createExplosion:FireServer("chad_universal")
#RemoteFunction
###Now a remote function. They do not have any event to listen for, you instead assign it a callback. An example for using a remote function would be to check the price for a house, then the client could request the price. Remote functions must return, so that the client could get what the server returns to it, or vice versa if you're doing server to client. If you don't need to return anything use an event instead.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local checkPrice = Instance.new("RemoteFunction")
checkPrice.Name = "CheckPrice"
checkPrice.Parent = ReplicatedStorage
local function getPrice(player)
local price = workspace.House.Price
if player.leaderstats.Cash.Value >= price.Value then
end
return workspace.House.Price.Value
end
checkPrice.OnServerInvoke = getPrice
###From the client:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local checkPrice = ReplicatedStorage:WaitForChild("CheckPrice")
local price = checkPrice:InvokeServer()
print(price)