How Would I Move A Part From Where It Is Touched? (SOCCER HEADER SYSTEM, HELP STILL NEEDED)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am making a soccer game. When the ball is midair, you can jump and if you touch the ball hitbox, the ball is sent forward and up in your direction.
Currently, because I am using the touched event even though I immediately turn a variable so the ball can’t be headered, the ball is still headered up to several times. I also want the force/direction of the ball to range from where you hit the hitbox. E.g middle of hitbox == straight up, from behind == forward, and so on, so if the ball is moving slower/faster than you it doesn’t go past you or behind you after a few jumps.

  1. What is the issue? Include screenshots / videos if possible!

I am not sure how to go about the touched issue, aside from maybe using a getpartsinpart while loop which is inefficient and probably won’t work because of a thing in my script, and I’m not sure how’d I go about sending a part opposite from where it was hit.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried searching on the forum and experimenting.

--script
BALL.HeaderHitbox.Touched:Connect(function(hit)
	if not hit.Parent or hit.Parent and hit.Parent == workspace then
		return
	end
	if BALL.InPossession.Value == false and hit.Parent:FindFirstChildOfClass("Humanoid") and BALL.CanSteal.Value == true then

		if BALL.Position.Y >= 3 and hit.Parent:FindFirstChild("Humanoid").FloorMaterial == Enum.Material.Air then
			
				game.ReplicatedStorage.Sounds.Header:Play()
				BALL.CanSteal.Value = false
				BALL.AssemblyLinearVelocity = Vector3.new(hit.Parent.HumanoidRootPart.CFrame.LookVector.X, 2.5, hit.Parent.HumanoidRootPart.CFrame.LookVector.Z) * 25

				task.wait(0.1)
				BALL.CanSteal.Value = true
			
		end

	end
end)
--client
(part of inputconnected)
elseif inp.KeyCode == Enum.KeyCode.Space then
		if not player.Character:FindFirstChild("Ball") then
			return
		end
		
		player.Character.Animate.fall.FallAnim.AnimationId = "rbxassetid://90181425663093"
		player.Character.Animate.jump.JumpAnim.AnimationId = "rbxassetid://82089533067053"
		player.Character.Humanoid.FreeFalling:Connect(function(active)
			if not active then
				player.Character.Animate.fall.FallAnim.AnimationId = "rbxassetid://126983242151101"
				player.Character.Animate.jump.JumpAnim.AnimationId = "rbxassetid://74861334091368"
			end
		end)
		game.ReplicatedStorage.RemoteFunctions.RainbowFlickFunction:InvokeServer(player.Character.HumanoidRootPart.CFrame.LookVector)

Heyo!

I would switch to GetPartsInBoundingBox() and leave Touched() in the past as GetPartsInBoundingBox() and there’s another one for a sphere radius I don’t know the function name they are overall better and more performant.

As for your question the way I would go about it is by making a global hitbox that does not rotate on the ball. Then separate the hitboxes into 2, Middle, and Back/Front. Then you should check if the Middle part was touched by the character, if it was you know it was a guaranteed touched in the middle on the SERVER, you can try and detect it on the client for more accuracy but acknowledge the risks of laggy clients, exploiters and many more edge cases you will have to handle. Then just apply the AssemblyLinearVelocity to the ball. It’s the way I would do it. I am not sure if it’s the best way since I never tried making a soccer game.

Someone else who may be more experienced can give you a pointing direction, but for now as no one responded this is the best I can come up with :slight_smile:

If you have any further questions let me know :smiley:

– Link To Article. Better Performant Ways Of Detecting Touched As Mentioned Above.

hey first of all thanks about the suggestion i just checked the diff between getpartsinpart and yeah ill switch, but the physic thing seems like it wont work since i need the hitbox to be precise and i want the change to be atleast 1 stud precise, and i need both the length width and height i could probably need like 125 hitboxes