How to use raycast result position and normal after the part has been moved?

So to specify my issue. I have a gun system in my game that uses raycasting. I use raycast result position and normal to position the bullet holes on a player when they get shot. However since the shots are determined on the client the replication acts up sometimes. So if I shoot a player and the bullet hole is placed using ray result position and normal sometimes the bullet hole will just be floating near where they got shot and not directly on them. How can I fix this?

To simplify the issue. How can I use the raycast result and raycast normal almost like a “Part Offset” so that I can always place the bullet hole in the right spot on a part / limb even if its cframe / position changes.

can’t you just weld the part with the bullet hole to the player? also I feel like player’s character don’t need bullet holes

1 Like

My game has injuries so the bullet holes are a must. And I already weld them. The issue is the rcpos and normal are determined and then it fires an event to the server which has a very slight delay which can result in the bullet hole floating.

you can use cframe:ToObjectSpace(cframe) to get the offset and send it to server

--// Client //--
local instance = raycastResult.Instance
local position = raycastResult.Position
local normal = raycastResult.Normal

local offset = CFrame.new(position):ToObjectSpace(instance.CFrame)
local cframe = CFrame.new(position, position + normal)
local offset = instance.CFrame:ToObjectSpace(cframe)

event:FireServer(offset, raycastResult.Instance)

--// Server //--
event.OnServerEvent:Connect(function(player, offset, instance)
	local cframe = instance.CFrame * offset
	
	bulletHole.CFrame = instance.CFrame * offset
end)
1 Like

For some odd reason this make the bullet hole appear on the opposite side of the part.

Or it just appears inside the part making the bullet hole not visible. Very odd

Not only does it appear weirdly. Its always facing forward so if I shoot the player in the back the decal for the bullethole is going to hidden since the front face is going to be the same as the part it hit.

yeah you gonna need to use raycastResult.Normal for that

also edited my previous post because I used cframe:ToObjectSpace() the wrong way

1 Like

Works like a charm now! Thank you so much for the help!

1 Like