The problem could be that the part is local which is why if you pass it to the server, the part will be nil since it is only visible to the client.
send extra variable âtypeâ
PlaceItemServer.OnServerEvent:Connect(function(player, Object, Type)
--[[
Object 1 is the type of part
Object 2 is the parts name
Object 3 is the parts CFrame
Object 4 is the parts size
]]
local Part = Instance.new(Type)
Part.Name = Object.Name
Part.CFrame = Object.CFrame
Part.Size = Object.Size
-- if part == part
if Type == "Part" then
Part.Shape = "Block"
if Type == "Mesh" then
Part.MeshId = Object.MeshId
end
end
end)
dramatically reduces code size off the bat
Then how do I get the server to get the block from the client? Right now, the PlacingModel is on the client, and once itâs cloned and destroyed it tries to send the new part to the server.
Why donât you just make the server create the part? Send the name of the object you want to make through the remote, and have the server create it. For example:
--Localscript
PlaceItem:FireServer("Door")
--Regular script
PlaceItem.OnServerEvent:Connect(function(Player, Item)
if Item == "Door" then
--Place door
end
end)
I was doing that with my original code, it creates the part and changes the properties to make it match.
You were sending the actual object in the code, not the name of it, which could cause problems.
The object sending part is for properties, I dont know a better way.
What exactly are you trying to accomplish? If youâre making a block placing system, for example, you can just pass the name of the block and itâs position.
All Iâm trying to make it do is duplicate the client sided block on the server basically.
The error should be fixed by doing:
if Object then
in front of the :IsA() thing. The object is nil, are you sure you are passing it through your remote?
All I pass through is the object that is an instance, and the Player, which should be removed because itâs not used.
Parts created on the client are seen as nil on the server when passed through a remote event.
If theyâre all the same size, then you can just send the position of them in the remote event. You can also send the part types and the size of it as well if those are different.
The only other way I can see doing it is I pass through the name of it, and in my module I have for furniture, I can make a part of the table âMeshIdâ or something, but that wouldnât work for models with more than 1 mesh.
Do not pass the player. The player is automatically passed by the client.
Then the object you pass is nil.
Just use models then. You could have a model named âDoorâ in a folder called âFurnitureâ in ReplicatedStorage, and just pass the name âDoorâ with the remote, and then have the server clone the model and place it.
So, the only other way I can see it is passing the name of it, then finding it in the Furniture folder, then cloning it. But then again, I dont know how to pass through the CFrame.
Just, pass the CFrame like anything else
--Localscript
RemoteEvent:FireServer("Door", PlacementCF)
--Regular script
RemoteEvent.OnServerEvent:Connect(function(Player, Item, CF)
local Object = Furniture[Item]:Clone()
Object:SetPrimaryPartCFrame(CF)
Object.Parent = workspace
end)
Here, not sure why but I got âString expected, got Instance.â on parameter 2, even though itâs sending the name.