Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

remote function or remote events. when to use which one?

Asked by 7 years ago

whats the main difference from remote functions and remote events? when is approppiate to use either?

2 answers

Log in to vote
0
Answered by 7 years ago

Say you wanted to get a value of the client while using FE, you would make a script like:

-- Server Script
rf = Instance.new("RemoteFunction", workspace)
rf.Name = "GetPlayerName"
-- Client Script
rf = workspace:WaitForChild("GetPlayerName")
rf.OnClientInvoke = function() -- Callback function
    return game.Players.LocalPlayer.Name
end
-- Other Server Script
print(workspace.GetPlayerName:InvokeClient(game.Players.SebbyTheGODKid))

That will print "SebbyTheGODKid"

But say you JUST wanted to use a remote event to place a block from the client:

-- Server Script
re = Instance.new("RemoteEvent", workspace)
re.Name = "PlaceBlock"
re.OnServerEvent:Connect(function(pos)
    if pos ~= nil then
        part = Instance.new("Part", workspace)
        part.Position = pos
    end
end)
-- Client Script
workspace.PlaceBlock:FireServer() -- Returns nothing, but places a block on the server even with FE.

Hope that helps!

Ad
Log in to vote
0
Answered by 7 years ago

Straight from roblox forum.

"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."

For a better description, you can go on the forum itself.

Link: http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions

I dont really know the difference myself, so I just used the wiki, lmao.

Answer this question