How to know when a player connected with any part and what position did they hit on the part?

I’m trying to make like where in battleground games when you get knockbacked into like a building or something, there will be like a crack decal or rock effect where you got smashed into it and I’m trying to figure out how to do that

You can use the Touched event to detect when a player hits a part.

Insert this LocalScript into the part (for example in a building wall)

local part = script.Parent

local function onPartTouched(h)
	local character = h.Parent
	local humanoid = character:FindFirstChild("Humanoid")

	if humanoid then	-- this will check if hit object is a player
		local player = game.Players:GetPlayerFromCharacter(character)	-- this will get player from character
		if player then
			-- this will get the collision point
			local collisionPoint = h.Position

			-- here im creating a crack effect or something like that
			local crackEffect = Instance.new("Part")
			crackEffect.Size = Vector3.new(1, 1, 1)
			crackEffect.Anchored = true
			crackEffect.CanCollide = false
			crackEffect.Position = collisionPoint

			local decal = Instance.new("Decal")
			decal.Texture = "rbxassetid://000000"  -- replace with a crack decal(image) id
			decal.Face = Enum.NormalId.Top
			decal.Parent = crackEffect

			crackEffect.Parent = game.Workspace

			-- this will destroy that crack effect after 5 seconds
			game:GetService("Debris"):AddItem(crackEffect, 5)
		end
	end
end

-- connecting the function to the Touched event
part.Touched:Connect(onPartTouched)

1 Like

This probably wouldn’t work as well as OP probably wants, because of how positions work. I’d reccomend just casing a raycast out onto the surface they want, in the direction such as behind or below the player. What your code does is check whenever a player is hit just in general by any player, wherever the part that hit the player is there’s a random crack effect that’s quite small. That’s not being hit by a building and a crack forming. Furthermore, positions are (by default) in the centre pivot of whatever part it’s in. That still wouldn’t be accurate.

1 Like

I’m thinking that sending a raycast in the same direction the knockback velocity is going would probably work, do you?

Yeah, as long as you exclude the player it should eventually find a wall/floor that you can then spawn a crack on with the position

1 Like

But the problem is, when I create a knockback I set a velocity and then delete the velocity so it’s realistic, but in this case when I fire the ray to the direction I set the knockback to, it wont go to where the player will actually land due to deleting the knockback

2 Likes