Why wont it work?

Hello,
im attempting to make a sort bullet hole kind of system and its working fine, except dat when the bullet lands on a obj like a wall, the bullethole gets rotated the exact oposite, check the video

Simply said, the bullet doesnt get rotated correctly.

if you know as to why please let me know. The code is:

if RayCast and RayCast.Instance then
			local bulletHole = game.ReplicatedStorage.GibBulletHole:Clone()
			bulletHole.Parent = RayCast.Instance
			bulletHole.Position = RayCast.Position
			bulletHole.CFrame = CFrame.new(bulletHole.Position, bulletHole.Position+ RayCast.Normal)
			local wc = Instance.new("WeldConstraint", bulletHole)
			wc.Part0 = bulletHole
			wc.Part1 = RayCast.Instance
			game.Debris:AddItem(bulletHole, 63)
end

Thanks.

Is the bullet hole a model? (as in an obj or fbx)

If so, then you should try rotating the model in the modelling software, if you’re using blender, make sure you’re exporting it with the transform included

Its mesh part, i have no access to the blender thingy, but i can try importing it into blender

try this:

if RayCast and RayCast.Instance then
			local bulletHole = game.ReplicatedStorage.GibBulletHole:Clone()
			bulletHole.Parent = RayCast.Instance
			bulletHole.Position = RayCast.Position
			bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + RayCast.Normal);
			local wc = Instance.new("WeldConstraint", bulletHole)
			wc.Part0 = bulletHole
			wc.Part1 = RayCast.Instance
			game.Debris:AddItem(bulletHole, 63)
end

this did nothing, it was the same

In that case, you could multiply the normal, i think you need to multiply it with a vector3, but not sure. Can’t say exactly how to do it, but i think that could work. Maybe try Vector3.new(1,2,1) or maybe add (+) it with Vector3.new(0,90,0)

maybe try multiplying it by CFrame.Angles(0,math.rad(90),0)

what could that vector be? I have no idea what a normal even is. I followed a tutorial allong, ik what all the others do but not what a normal is. Might look at the docs.

Try savi’s solution first, I think he’s right, if it doesn’t work, try the vectors i included in my edit

Putting it inside: bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + RayCast.Normal);
gives a error, and putting it just outside wont do anything.

May I ask what the error says?

20:46:00.056 Workspace.MP5SD.Server:58: invalid argument #1 (CFrame expected, got Vector3) - Server - Server:58

Did you try this? bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + (RayCast.Normal * CFrame.Angles(0,math.rad(90),0));

bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + (RayCast.Normal * CFrame.Angles(0,math.rad(90),0)));

gives the same error as 20:46:00.056 Workspace.MP5SD.Server:58: invalid argument #1 (CFrame expected, got Vector3) - Server - Server:58

Try this:

if RayCast and RayCast.Instance then
            local bulletHoleFolder = workspace:FindFirstChild("BulletHoleFolder") or Instance.new("Folder",workspace)
            bulletHoleFolder.Name = "BulletHoleFolder"

			local bulletHole = game.ReplicatedStorage.GibBulletHole:Clone()
			bulletHole.Parent = bulletHoleFolder
			bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + RayCast.Normal);
			game.Debris:AddItem(bulletHole, 63)
end

I think the normal is a vector3 actually, try changing CFrame.Angles(0, math.rad(90),0) to Vector3.new(1,90,1)

if i do

bulletHole.CFrame = CFrame.lookAt(RayCast.Position, RayCast.Position + (RayCast.Normal + Vector3.new(1,90,1)));

then it becomes wacky and doesnt really change anything besides placing it at random rotations

Multiply it instead of adding it(RayCast.Normal * Vector3.new(1,90,1)));

that is the same as not adding it or doing allat, ( the same as

CFrame.new(bulletHole.Position, bulletHole.Position+ RayCast.Normal)

)

If this doesn’t work I have a script that I made a few months ago that you could experiment with:

RunService.Stepped:Connect(function()
	local raycaster = script.Parent
	
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {raycaster, dotFolder:GetChildren()}
	
	local range = 100
	
	local origin = raycaster.Position
	local dir = raycaster.CFrame.LookVector.Unit * range
	
	local result = workspace:Raycast(origin, dir, params)
	
	
	if result ~= nil then
			dot.CFrame = CFrame.lookAt(result.Position, result.Position + result.Normal);
		end
	
end)