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??
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…
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.