Sent CFrame is not same as received CFrame

I have a placement system with an issue where it does not send the correct CFrame values when sending it via remotevent from local script to server script.

The placement system creates a hologram of what the player is gonna place, the player then adjusts the position using their mouse to their liking which all is happening localy which then sends a remotevent signal to a server script and inputs the placement name and the placement CFrame.

Yet CFrame value is not being sent correctly to server script makes the placement go through the other instances in the workspace

Here is a print of what the local script is sending and what the server is receiving.

1 Like

It could be either floating point error, or have you possibly changed or interrupted the CFrame whilst passing from client to server or has it been changed anywhere in the code?

2 Likes

Can you show the sending part of your script?

3 Likes
PlacementTool.Activated:Connect(function()
				Hologram_Moving:Disconnect()

				PlaceObject:FireServer(Hologram_Placing_Object.Name, Hologram_Placing_Object.PrimaryPart.CFrame)
				print("sent",Hologram_Placing_Object.PrimaryPart.CFrame)
				
				PlacementTool:Destroy()
				Hologram_Placing_Object = nil
			end)
3 Likes

Ok can you show the receiving function?

1 Like

Most likely because the of the transmission of data from the client to server, it often gets converted to a format that is more efficient for transmission. In your case, the rotation part of the CFrame (the last 9 values) is being rounded. But this shouldn’t be a problem because the difference you get is only by about 0.0000000437113883. Maybe try converting the CFrame to a string, and on the server, reformat it back to a CFrame?

1 Like
PlaceObject.OnServerEvent:Connect(function(Player, ObjectName, Position_Orientation)-- posY, posZ)
	local Found_Object = Placable_Objects:FindFirstChild(ObjectName):Clone()
	-- Adjusts the found object
	Found_Object:SetPrimaryPartCFrame(Position_Orientation)
	print("Recieved",Position_Orientation)
	Found_Object.Parent = Placed_Objects
	
	Update_CollectionService()
end)
1 Like

On the sending print there is a value -4.37 that one is not printing on recieved, I’ll try do that too

1 Like

If you look closely, it says -4.37113883e-08, which if you type into the calculator, it gives you -4.37113883 * 10⁻⁸. A number times 10 to the power of n tells you how much zeros the number contains. In this case, -8. Which if you type out, is: 0.0000000437113883 or simply 0. What appears to be a large number is in reality only a very small number.

So to summarize it: Your CFrame is being sent correctly, with a tiny precision loss. It’s not actually -4.37

1 Like

1 Like

That’s more likely an issue of how you are trying to set the CFrame, can you show how you create it on the server side? Sending the CFrame from client to server seems not to be the problem here.

I can show you how the hologram CFrame is being set.

Hologram_Moving = Mouse.Move:Connect(function()
				local result = MouseRaycast({Hologram_Placing_Object})
				
				if result and result.Instance then
					posX = result.Position.X
					posZ = result.Position.Z
					
					local orientation, Size = Hologram_Placing_Object:GetBoundingBox()
					
					posY = result.Position.Y + Size.Y - (Size.Y / 2)
				end
				
				orientationY = Hologram_Placing_Object.PrimaryPart.Orientation.Y
				orientationZ = Hologram_Placing_Object.PrimaryPart.Orientation.Z
				orientationX = Hologram_Placing_Object.PrimaryPart.Orientation.X

				-- Set the primary part CFrame for the hologram placing object
				if posX ~= lastposX or posZ ~= lastposZ or posY ~= lastposY then
					Hologram_Placing_Object:SetPrimaryPartCFrame(CFrame.new(posX, posY, posZ) * CFrame.Angles(math.rad(orientationX), math.rad(orientationY), math.rad(orientationZ)))
					print("HOlo",Hologram_Placing_Object.PrimaryPart.CFrame)
					lastposX, lastposZ, lastposY = posX, posZ, posY
				end

			end)

This is how its being set on server side

The issue is probably because of how you calculate posY, You’re setting posY to be the Y position of the raycast result plus the size of the hologram, minus half the size of the hologram. But If you want the hologram to be placed on top of the ground (or whatever object the raycast hits), you should set posY to be the Y position of the raycast result plus half the size of the hologram.

if result and result.Instance then
    posX = result.Position.X
    posZ = result.Position.Z

    local orientation, Size = Hologram_Placing_Object:GetBoundingBox()

    posY = result.Position.Y + (Size.Y / 2)
end

I tried it but it behaved like the previous still placing the table under the floor and the bed some studs above the floor floating

:GetBoundingBox() could be an issue as well, If your hologram has parts that are not axis-aligned, the bounding box might be larger than you expect.

Try the following instead:

if result and result.Instance then
    posX = result.Position.X
    posZ = result.Position.Z

    local orientation, Size = Hologram_Placing_Object:GetBoundingBox()
    local primaryPartPosition = Hologram_Placing_Object.PrimaryPart.Position
    local bottomOffset = primaryPartPosition.Y - (orientation.Y - Size.Y / 2)

    posY = result.Position.Y + bottomOffset
end

bottomOffset is the distance from the PrimaryPart to the lowest point in the hologram. By adding this offset to result.Position.Y , we ensure that the lowest point of the hologram is placed on the ground, regardless of where the PrimaryPart is.

YAP IT WORKED FINALLYYyyyyaaaWW

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.