Using instances and remote functions

If I require a RemoteFunction that spawns a part in a localscript and use it is the part spawned locally or globally?

Your sentence is not meaningful. If you fire it from the client, you can do it on the server and return the callback. You can fire it from the server but you can do it in the client. Depends on where you are firing and receiving it.

Client -> Server -> Client --Globally

--Client

game:GetService("ReplicatedStorage").RemoteFunction:InvokeServer() 
print("Invoke is done!")

--Server

game:GetService("ReplicatedStorage").RemoteFunction.OnServerInvoke = function(player)
    local part = Instance.new("Part")
    part.Parent = game.Workspace
    part.Name = "Tutorial"

    return "Received the invoke"
end

Server -> Client -> Server --Locally

--Server

game:GetService("Players").PlayerAdded:Connect(function(player)
    game:GetService("ReplicatedStorage").RemoteFunction:InvokeClient(player)
    print("Invoke is done!")
end

--Client

game:GetService("ReplicatedStorage").RemoteFunction.OnClientInvoke = function()
    local part = Instance.new("Part")
    part.Parent = game.Workspace
    part.Name = "Tutorial"

    return "Received the invoke"
end
1 Like

I am not understanding :shallow_pan_of_food:

What do you need exactly? ----

1 Like

Why the shallow pan of food emoji?

Character requirement :shallow_pan_of_food:

1 Like

I am making a script that locally detects when mousebutton1 is down and then creates a part

In simple words, it is equal to Remote Event BUT it may or may not return something:

Local
Remote = game:GetService("ReplicatedStorage").RemoteFunction
if Remote:InvokeServer(2)  then
	print("Yeah!")
else
	print("Upss")
end
Server
Remote = game:GetService("ReplicatedStorage").RemoteFunction

Remote.OnServerInvoke = function(player,N)
	if 4 + N == 6 then
		return true
	end
end

if it does not return something it will be nil
It works for what you want but it depends on where the listener is (local or server)

Do you need to create a part for the server or the client?

So I can make it so when the click happens the event triggers and passes the block to be placed as an argument, then have it return?

Yep, no need to return something, you could do it to report a bug to the player

I want to create the part on the server.

I recommend you to use RemoteEvents instead of RemoteFunctions. Because you don’t need to return anything.

2 Likes

Oh ok, glad to hear that cause its what im already doing.

RemoteFunctions are easily understandable but more complex than RemoteEvents. You can just code the communication way and method like

Client - Server - Script
            |
            |
            v
        Globally
------------------------
Server - Client - Server
           |
           |
           v
        Locally

Reminder to choose the middle of the line.

So you can just provide this with a RemoteEvent, RemoteFunctions are generally used to inform the client whether the function was successfully handled.

You can do this with a RemoteEvent.

--Client

script.Parent.Activated:Connect(function()
    game:GetService("ReplicatedStorage").RemoteEvent:FireServer()
end)

--Server
--
game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(player)
    local part = Instance.new("Part")
    part.Parent = game.Workspace
    part.Name = "Tutorial"
end)