Basic Help with RemoteFunctions

I decided that today, after a week or so of struggling with Remote Functions, that I was going to go back to the wiki and simply start with the code that is provided there and then use my understanding of that code to move onto making my own Remote Functions.

Unfortunately, it seems that the wiki is outdated, flawed or not updated, as the script provided which I’m trying to learn from returns an error. I have made 0 changes to the script, and have made sure that the capitalization is all correct.

Server Script in Server Script Service:

local RS = game:GetService("ReplicatedStorage")
local CreatePartRequest ="RemoteFunction")
CreatePartRequest.Parent = RS
CreatePartRequest.Name = "CreatePartRequest"

local function onCreatePartRequested(player)
print(player.Name, " wants to spawn a new part")
local newPart ="Part")
newPart.Parent = game.Workspace
return newPart

CreatePartRequest.OnServerInvoke = onCreatePartRequested()

Local script in the PlayerGui:

local RS = game:GetService("ReplicatedStorage")
local createPartRequest = RS:WaitForChild("CreatePartRequest")
local newPart = createPartRequest:InvokeServer()
print("The server created this part for me:", newPart)

Once the code works, the next step for me is figuring out how the client knows when to invoke the server if it’s not embedded in an event.

You are calling the function onCreatePartRequested on line CreatePartRequest.OnServerInvoke = onCreatePartRequested()

This means you are setting OnServerInvoke to the newPart you return in the function. Instead just set the OnServerInvoke to the function onCreatePartRequested

Like This:

CreatePartRequest.OnServerInvoke = onCreatePartRequested
1 Like