Basically In my game I use a local input to create 2 parts from the server and then return them to the client but for some reason the parts print normally in the Remote Function but when returned on the client they print as Nil. I know that returning a part made on the client will always be nil but I’ve never experienced the opposite like how I am right now.
code:
--SERVER
game.ReplicatedStorage.CreateUnion.OnServerInvoke = function(plr,part,sliceCF,sliceDirection)
local newPart = part:Clone()
newPart.Name = "NewPart"
local slicePart = part:Clone()
slicePart.Name = "SlicePart"
slicePart.Size = Vector3.new(20,20,20)
slicePart.Anchored = true
slicePart.CanCollide = false
slicePart.CastShadow = false
slicePart.CFrame = sliceCF:ToWorldSpace(CFrame.new(Vector3.new(0,sliceDirection*slicePart.Size.Y/2,0)))
slicePart.Parent = workspace
return newPart,slicePart
end
--CLIENT
function module:SlicePart(part,posY,orientation)
local sliceCFrame = CFrame.new(Vector3.new(part.Position.X,posY,part.Position.Z))*CFrame.Angles(orientation.X,orientation.Y,orientation.Z)
local bottomPart,bottomSlice = game.ReplicatedStorage.CreateUnion:InvokeServer(part,sliceCFrame,-1)
local topPart,topSlice = game.ReplicatedStorage.CreateUnion:InvokeServer(part,sliceCFrame,1)
print(bottomPart,topPart) --printing both as nil
end
Let me guess, you have StreamingEnabled turned on by default?
Basically, for remoting instances, the server is just sending a unique id to the client, and it gets internally picked back up if a coinciding instance exists.
This should work fine under normal circumstances because instances are replicated reliably (as opposed to unreliably, like physics or attributes), however streaming screws this all up by not replicating instances unless the client is ‘reasonably’ close enough to where the instance appears. Thus, instances might not ever be replicated, and your remotes are sending nils.
Parenting to persistent models doesn’t fix this either, because they still do some form of deferring for replication. Unless you want to write some racecondition-prone code to try and pick the instance back up, you should just disable streaming like 99% already do.
The problem was that clones load in super late and also dont get cloned properly to the client. Not exactly what the technical way of say this is but basically I had to put a task.wait of 1 if I wanted to get the part so instead I just made new part and matched their properties.