Im trying to make a drawing system to draw on every surface like the game spraypaint. but the part is on the wrong orientation but correct on one orientation only here is a example of that happening:
local script:
(unnecessary pieces of code not included)
local pos = mouse.Hit
local result = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000)
local normal = result.Normal
script.DrawEvent:FireServer(pos,normal.X*90,normal.Y*90,normal.Z*90)
server script:
(unnecessary pieces of code not included)
The thing is, normal is not the actually the same as Euler angles rotation (which is used in your case).
Normal is the vector, that goes perpendicular to the plane that your raycast hits.
The easiest way you can implement what you’re trying to is:
Local part:
local pos = mouse.Hit.p
local result = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 1000)
local normal = result.Normal
script.DrawEvent:FireServer(pos, normal) -- Just send pos and normal
Server part:
script.Parent.DrawEvent.OnServerEvent:Connect(function(player, pos, normal)
local part = Instance.new("Part")
-- (CFrame that starts in pos, and looks to the point pos + normal)
part.CFrame = CFrame.new(pos, pos + normal) * CFrame.Angles(0, math.pi/2, 0)
part.Parent = folder
part.Anchored = true
part.Shape = Enum.PartType.Cylinder
part.Size = Vector3.new(layer,width,width)
part.Material = Enum.Material.SmoothPlastic
part.Color = Color3.fromHSV(h,s,v)
part.CanCollide = false
part.CanQuery = false
part.CanTouch = false
part.Name = "DrawPart"
local lval = Instance.new("NumberValue")
lval.Name = "Layer"
lval.Parent = part
lval.Value = layer*100
end)
The best part is, this approach will work on any kind of rotated instance, not just the basic block rotated strictly 90 degrees!
From what I see, everything should be fine. Both pos and normal are passed to the server, so in no way pos + normal should be equal to nil. Check out if the code was properly copied from what I have send.
That basically means, all of the values are calculated properly. Means, there is no problem in the code logic itself. Otherwise, you would have got the same error during the printing. Try to do it step by step:
local newCFrame = CFrame.new(pos, pos + normal)
print(newCFrame)
part.CFrame = newCFrame
print("CFrame is correct")