Making a crack when a player touched a wall with knockback

basically im making a knockback system when the player hits any wall in game, i want a cracked decal too pop up behind him. i tried using instance .new too make a part the set its offeset -1 behind the player then putting the decal on that with the player touched the wall but instead it started spaming the decal everywhere instead of one time hiting the wall heres my knockback if needed.
also i tried using get children for getting every wall in the game but no luck any help with that would be great

For starters, use part.Touched on the wall. If there’s more than 1 wall you’d like this to work with you can still use GetChildren() like so.

for i,v in pairs(model:GetChildren()) do
	v.Touched:Connect(function()
	end)
end

Now, once a dummy touches a wall, you can anchor them and create the cracked image with Instance.new(). Now, a challenge is placing the cracked image in the right spot. You can start off by by getting the dummy’s HumanoidRootPart’s X,Y, & Z position.

This is the tricky part though. You’ll need to figure out if we need to edit the X, Y, or Z position so that it matches perfectly with the wall. Because this is a wall, I assume all of your walls will have a long flat side. If this is true , I would figure this out by going to size and comparing the X, Y, & Z numbers to find which side the longest. Let’s say X is the longest. That would mean we would have to change the X position of the cracked image to the exact X position of the wall. Does that make sense? If it does, but you don’t get why this works, try it out.

If any of your walls happen to be rotated like 35 degrees and not 90 or 0, you may also have to set the cracked image’s orientation to the same as the wall.

This is probably not the best way to do this, but it is easy and it does work. But, I hope I’ve given you ideas on how to accomplish what you’re trying to do. Good luck!

2 Likes

thanks alot! i will try this right now

I just realized the positioning technique won’t always work. I’ll think about it a bit more though and let you know if there’s something else you can do. Got any ideas though?

Touched events aren’t necessarily accurate. You can use the velocity as a direction and raycast to detect walls and you get a position result from raycasting as well as the surface normal.

1 Like

hm, what i was gonna do is use what you said clone a part but set its position too right behind the player but changeing the z axis to -1 moving it back heres what i got down rn tho

	for i,v in pairs(walls:GetChildren()) do
							v.Touched:Connect(function()
								wallhitsound:Play()
								local crackpart = game.Workspace.CrackPart
								
								local cracked = Instance.new("Decal")
								cracked.Parent = crackpart
								cracked.Texture = "http://www.roblox.com/asset/?id=29268434"
								crackpart.Size = Vector3.new(8.8, 8.6, 2)
								crackpart.Position = Vector3.new(v,v,-1)
								crackpart.Anchored = true
								
								wait(1)
								crackpart:Destroy()
								GetRoot.Anchored = false
								wait(1)
								crackpart:Clone()
								crackpart.Name = "crackpart"
							end)
						end