Hello there,
I am working on my game right now, and just started working on the engine this week. I have a function that creates an object on the server, and then returns that object. It seems to work fine when I am returning the object from the server to the client, however, the part does not get returned when the situation is flipped around. I tried to return a part made on the client, but it wouldn't return the object and just kept returning nil.
So I am wondering if this is because of a roblox issue and I need to find an alternative to accomplish this task, or is it just something wrong with my code. I will post the code below so you can analyze exactly what I mean.
-- Server - Client Function --
local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("Instance Work")
local instance_func = folder:WaitForChild("Instance")
------------------------------------------------------
-- Creates a part on the server --
local function instance(plr, obj, props)
local object = Instance.new(obj)
for prop, value in next, props do
if prop == 'Parent' then
value = return_obj_from_string(value)
end
object[prop] = value
end
if object then return object end
end
instance_func.OnServerInvoke = instance
-- Creates a part on the server --
------------------------------------------------------
####The above will create an object on the server and then successfully return that object to the client.
-- Client - Server Function --
local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("Instance Work")
local instance_func = folder:WaitForChild("Instance")
------------------------------------------------------
-- Creates a part on the client --
local function instance(obj, props)
local object = Instance.new(obj)
for prop, value in next, props do
if prop == 'Parent' then
value = return_obj_from_string(value)
end
object[prop] = value
end
if object then return object end
end
instance_func.OnClientInvoke = instance
-- Creates a part on the client --
------------------------------------------------------
####The above creates an object on the client, however, it fails to return the object to the server.
####The code below is how I made the call to the client from the server and how it failed to return the part.
-- Script inside Click Detector, which is inside a part and meant to activate the client function upon clicking the part --
local detector = script.Parent;
local rs = game:GetService("ReplicatedStorage");
local instance_folder = rs:WaitForChild("Instance Work")
local instance = instance_folder:WaitForChild("Instance")
detector.MouseClick:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait();
local root = char:WaitForChild("HumanoidRootPart");
local props = {
['BrickColor'] = BrickColor:random();
['Transparency'] = math.random();
['Anchored'] = true;
['CanCollide'] = false;
['Material'] = Enum.Material.Neon;
['CFrame'] = root.CFrame;
['Parent'] = workspace;
['Name'] = 'Innovation';
}
print("It is:", instance:InvokeClient(plr, 'Part', props)) -- Prints "It is: nil"
end)
##Thank you for any help and hope you have a nice day/night.
Best regards,
IdealistDeveloper

3 comments
you have to have the server create the object not the client. If you let the client handle it, the server would always receive it as nil.
It's fine not to format everything. /shrug
So, it is impossible for the server to get a reference to a part on the client?