I was trying to learn how to use remote events and what they do but i still dont know it, can anyone help?
COMMUNITY QUESTION
Can anyone teach me how to use remote events?
1 answer
Remote events are extremely easy! They help you run server scripts from a local script, or local scripts on server scripts. They are really useful. Remote events are normally stored inside ReplicatedStorage so the client and server can access them.
Firstly create an RemoveEvent inside the ReplicatedStorage. After we insert a Local Script inside the PlayerGui.
Inside of that local script:
local UserInputService = game:GetService("UserInputService") -- The service UserInputService.
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- The service ReplicatedStorage.
local Event = ReplicatedStorage:WaitForChild("RemoteEvent") -- Waits for the event you made.
UserInputService.InputBegan:Connect(function(Key) --When a key pressed this event runs.
if Key.KeyCode == Enum.KeyCode.E then --Checks if the key is "E".
Event:FireServer(Player) --Fires the server.
end
end)
And then we can create a Server Script inside the ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- The service ReplicatedStorage.
local Event = ReplicatedStorage:WaitForChild("RemoteEvent") -- Waits for the event you made.
Event.OnServerEvent:Connect(function(Player)) --When you fire the remote event, this event runs.
print(Player.Name.. "pressed the E key.) --This prints the player's name.
end)
Here's more information about it. https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
no that wont print players name you need to type it inside function so Event.OnServerEvent:Connect(function(player)
oh and local script doesnt even know what Player is so local Player = game.Players.LocalPlayer
so many mistakes inside your scripts :/
i was about to correct the server script but my internet went down and gave up.
and two "Player" is a argument, theres no need for "local Player = game.Players.LocalPlayer"