Roblox RemoteEvents Tutorial — Client-Server Communication Explained (2026)

Roblox RemoteEvents Tutorial

Why You Need RemoteEvents

In Roblox, code runs in two places:

RemoteEvents let these two sides communicate.

The 4 Communication Types

Code Examples

Client → Server (Most Common)

-- ReplicatedStorage: Create a RemoteEvent called "BuyItem"

-- Client (LocalScript):

local buyEvent = game.ReplicatedStorage:WaitForChild("BuyItem")

script.Parent.MouseButton1Click:Connect(function()

buyEvent:FireServer("Sword", 100)

end)

-- Server (Script):

local buyEvent = game.ReplicatedStorage:WaitForChild("BuyItem")

buyEvent.OnServerEvent:Connect(function(player, itemName, price)

-- ALWAYS validate on server! Never trust client data!

local actualPrice = ITEM_PRICES[itemName]

if not actualPrice then return end -- Invalid item

if player.leaderstats.Coins.Value >= actualPrice then

player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - actualPrice

giveItem(player, itemName)

end

end)

Server → Client

-- Server:

local notifyEvent = game.ReplicatedStorage:WaitForChild("Notify")

notifyEvent:FireClient(player, "You unlocked a new area!", "success")

-- Client:

notifyEvent.OnClientEvent:Connect(function(message, messageType)

showNotification(message, messageType)

end)

Security Rules

🔒 NEVER trust client data!

-- ❌ BAD: Client tells server how much damage to deal

buyEvent.OnServerEvent:Connect(function(player, damage)

enemy.Health = enemy.Health - damage -- EXPLOITABLE!

end)

-- ✅ GOOD: Server calculates damage itself

buyEvent.OnServerEvent:Connect(function(player, targetId)

local weapon = getPlayerWeapon(player)

local damage = weapon.Damage -- Server-side value

local target = findTarget(targetId)

if isInRange(player, target) then

target.Health = target.Health - damage

end

end)

Skip the Hard Part — Use Roblox Factory

Roblox Factory generates your entire game — 13+ Lua scripts, art, marketing — in one click for $29/month.

👉 Try Roblox Factory Now →


All articles · Roblox Factory · Game & Anime ARMY