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.
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?
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?
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
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)
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
: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.