I’m making a block placement system and I currently have a remote function handled by the server that when called return the cloned object instance to the client. here’s the code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local placeObjectFunction = ReplicatedStorage.Functions.PlaceBlock
local PlacementValidater = require(ReplicatedStorage.PlacementValidater)
local function placeBlock(...)
if not PlacementValidater:isWithinMaxDistance(player, position) or not PlacementValidater:isWithinGrid(position) then return end
if not PlacementValidater:canBePlaced(position) then return end
local block = blockTemplate:Clone()
if block:IsA("Model") then
block:SetPrimaryPartCFrame(CFrame.new(position) * CFrame.Angles(0,math.rad(blockOrientation.Y), 0))
else
block.CFrame = CFrame.new(position) * CFrame.Angles(0,math.rad(blockOrientation.Y), 0)
print(block.Transparency)
end
block:SetAttribute("OwnerId", player.UserId)
block.Parent = workspace.Blocks
return block
end
placeObjectFunction.OnServerInvoke = function(...)
local placedBlock = placeBlock(...)
print(placedBlock)
return placedBlock
end
I tried printing the instance on the server, and no error occur. Until we pass the instance to the client. (prob a replication latency issue)
CLIENT CODE:
local block
if ... then
block = block = placeBlockFunction:InvokeServer(...)
else
block = block = placeBlockFunction:InvokeServer(...)
end
-- wait for it to replicated
task.wait(1)
print(block)
And it gives me an error, even if I’m waiting a bit
The instanced returned is a clone of an instance inside of replicated storage, and gets parented to a folder in the workspace called Blocks
Would love to fix this!