Hello so i'm trying to Instance serversided parts from a localscript using a remoteevent and i keep getting this error.
local function instance(a,b) if b then return game:GetService("ReplicatedStorage").Instance:FireServer(a,b) elseif not b then return game:GetService("ReplicatedStorage").Instance:FireServer(a) end end local cool = instance("Part", workspace) print(cool) -- Supposed to print part name but prints nil instead
Anyway to fix this?
theres a few problems.
don't use the parent parameter for instance.new, its slow. (only set the parent param if you aren't gonna change any other properties. Otherwise, set the parent property last)
(main problem). you aren't returning the part you instance.new()ed in the server, therefore its not working.
to fix 2, you need to use a remotefunction instead of a remoteevent.
here is the fixed script:
local script
-- local script function instance(a,b) if b then return game:GetService("ReplicatedStorage"):WaitForChild("Instance"):InvokeServer(a,b) elseif not b then return game:GetService("ReplicatedStorage").WaitForChild("Instance"):InvokeServer(a) end end local cool = instance("Part") -- don't use the parent parameter, its bad. check dev forum to know why cool.Name = "lol" print(cool.Name) -- Instances are not strings bruv, should print lol because I set the name to "lol"
server script
-- server script local RF = game:GetService("ReplicatedStorage"):WaitForChild("Instance") RF.OnServerInvoke = function(class:string, parent) -- yes you can do this now local newPart = Instance.new(class) if parent and parent:IsA("Instance") then newPart.Parent = parent end return newPart -- this part you are missing end