RemoteFunction.OnClientInvoke returns nil for an instance

I want to create a part in the player’s workspace, through a Server script (the server will tell to LocalScript which part should be created).

So I have this on the Server:

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

local function onPlayerAdded(player)
	local PartInstance, TestValue = RemoteFunction:InvokeClient(player, "MyPart")
	print(PartInstance, TestValue)


… and this on LocalScript:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local RemoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")

local function CreatePart(PartName)
	local PartInstance ="Part", workspace)
	local TestValue = 1234
	PartInstance.Name = PartName
	print(PartInstance, TestValue)
	return PartInstance, TestValue

RemoteFunction.OnClientInvoke = CreatePart

The Part is correctly created on the player’s workspace in LocalScript. However, the instance is being received as nil in the server:


What’s wrong?

1 Like

The part is created on the client, the server can’t see the part because things created on the client are only visible for the client that created it


I was going to say what you just said but you beat me to it lol

1 Like

However, if I create a part in workspace through server, this part will be replicated for all players.
In short, there’s no way to create a part for a specific player through server…

You can make client only parts through the server with Remotes, but like what happened, trying to retrieve that part from the server will return nil, if you want that part to be seen by the server, there’s no real way besides making it on the server unfortunately, you’d need remotes to communicate with that

This is really disconcerting…
Everything that is done in LocalScript can be changed by exploiters.
Thus, I’m trying to avoid LocalScript as much as possible.
So, I thought about creating the parts for specific players by Server.
But parts created by the server are replicated to ALL players.
And now, parts created by LocalScript are not visible by the server… :roll_eyes:
I’ll have to go back to square one and make my code vulnerable to exploiters…