Help Fixing Build System!

When I try to send Data to the server its giving me an error here is the function that sends information in a local script

local function PlaceObject(Key, Processed)
	if not Processed and Key.UserInputType == Enum.UserInputType.MouseButton1 then
		if NewObject then
			if CanPlace == true then
				BuildEvent:FireServer(NewObject)
				NewObject = nil	
				IsPlacing = false
				CanPlace = true
			end
		end
	end
end

here is the script that receives the data

BuildEvent.OnServerEvent:Connect(function(plr, Object)
	
	print(Object)
	
	for i, part in pairs(Object:GetChildren()) do
		
		if part:IsA("BasePart") then
			part.Transparency = 0
			part.Material = Enum.Material.SmoothPlastic
			part.CanCollide = true
		end
	end
end)

when I print object its saying nil why is it not picking the data Up??

1 Like

Did you tryed to check the object from client? Maybe you sending nil object to server?

Check if object exists on server. If it exists only on client - server won’t see it and will throw an error.

Yes, objects that was created from client cannot be sended to server, for server object will not exist.

Instead of passing the object as an argument to the server, try sending information about the object and then recreating the object on the server. e.g object CFrame, object type…

its not appearing on the server cuz its a client part but the client will send the client part to the server won’t it?

I will try this thankk you! ill let u know if it works

Wait, just to let you understand. The reason it doesn’t work could be that it doesn’t exist on the client, the object needs to be replicated to the client so yeah. But also, you can only send values through remote events. If “NewObject” is located in repstorage or something you can send the name of the object instead… And check if the name matches any objects in repstorage. If it does, do your thing.

With remote events/functions, you can’t send full part, only basic data, such as strings, numbers, tables. But also, you can send LINKS of objects via remote events/functions. Cuz part not exists on server, you give server link to a non-existant part, and server can’t find it.

When you send an Instance through a remote, it only sends a reference to that Instance, so think of it like trying to read a variable.

If I do this:

local A = function()
  -- Local is like the client in this case, it's only making this variable on the client!
  local B = "I'm a part! I am located in Workspace under the name Part!"
  -- This is essentially what is sent to the server, but in reality it's binary data that points to the actual Instances.
end

A() --> This is your attempt to use FireServer to send the part to the server

print(B) -- The server tries to find that part, but... It doesn't exist in the scope of the server!
-- So we get nil.

I hope this helps, it’s just a matter of Serialization now, or use IDs and an array that matches on both the server and client to identify certain parts.

thanks everyone for helping I have figured it out by passing the objects name and frame ty