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 = Instance.new("RemoteFunction") RemoteFunction.Parent = game.ReplicatedStorage RemoteFunction.Name = "RemoteFunction" local function onPlayerAdded(player) local PartInstance, TestValue = RemoteFunction:InvokeClient(player, "MyPart") print(PartInstance, TestValue) end Players.PlayerAdded:Connect(onPlayerAdded)
… 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 = Instance.new("Part", workspace) local TestValue = 1234 PartInstance.Name = PartName print(PartInstance, TestValue) return PartInstance, TestValue end 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: