Football/soccer ball position isn't in front of player's foot

the football is supposed to be right infront of the player’s foot not on the ground, considering the roblox cframe is weird

script:

local futbol = script.Parent

futbol.Touched:Connect(function(hit)
	futbol:SetNetworkOwnershipAuto()
	if hit then
		if hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player then
				futbol:SetNetworkOwner(player)
				futbol.Parent = player.Character:FindFirstChild("RightFoot")
				if futbol.Parent == player.Character:FindFirstChild("RightFoot") then
					futbol.CanCollide = false
					local motor6d = Instance.new("Motor6D")
					motor6d.Parent = player.Character:FindFirstChild("RightFoot")
					motor6d.Part1 = futbol
					motor6d.C0 = CFrame.new(-0.10,0,-5)
					local weld = Instance.new("WeldConstraint")
					weld.Parent = futbol
					weld.Part0 = futbol
					weld.Part1 = player.Character:FindFirstChild("HumanoidRootPart")
					futbol.Position = player.Character:FindFirstChild("RightFoot").Position
					local foot = player.Character:FindFirstChild("RightFoot")
				end
			end
		end
	end
end)
1 Like

I think your problem is that you’re not considering that CFrame handles both Position and Orientation, so if you want to fix this, you should adjust the C0 of the Motor6D

Adjust this portion of your script:

motor6d.C0 = CFrame.new(0, 0, -0.5) -- Adjust position relative to foot

You can also adjust this portion of your script to help you be able to manually change the position of the football in relation to your foot.

 -- Position the football in front of the foot (if needed)
futbol.Position = player.Character:FindFirstChild("RightFoot").Position + Vector3.new(0, 0, -0.5)

If you have any further questions let me know!

1 Like

everytime i test the game, the ball goes to a different position but next the player

To make sure the football is positioned correctly in front of the player’s foot (rather than on the ground), you need to adjust the CFrame of the football according to the player’s RightFoot.

local motor6D = Instance.new("Motor6D")
    motor6D.Name = "FutbolAttachment"
    motor6D.Part0 = rightFoot
    motor6D.Part1 = futbol
    motor6D.C0 = CFrame.new(0, 0, -1.5) * CFrame.Angles(0, math.rad(90), 0)
1 Like

line 22 attempt to index nil with ‘position’

It seems you’re trying to position a football in front of a player’s foot using a Motor6D. Here’s a simplified approach to achieve this:

  1. Create the Motor6D: This will attach the football to the player’s foot.
  2. Set the C0 Property: Adjust the C0 property to position the football correctly.

Here’s an example script:

local futbol = script.Parent
local player = game.Players.LocalPlayer
local rightFoot = player.Character:WaitForChild("RightFoot")

-- Create Motor6D
local motor6D = Instance.new("Motor6D")
motor6D.Name = "FutbolAttachment"
motor6D.Part0 = rightFoot
motor6D.Part1 = futbol
motor6D.C0 = CFrame.new(0, 0, -1.5) * CFrame.Angles(0, math.rad(90), 0)
motor6D.Parent = rightFoot

Explanation:

  • CFrame.new(0, 0, -1.5): Positions the football 1.5 studs in front of the right foot.
  • CFrame.Angles(0, math.rad(90), 0): Rotates the football to align it properly.

Adjust the -1.5 value in CFrame.new(0, 0, -1.5) to position the football closer or further from the foot as needed.

This approach should help position the football correctly in front of the player’s foot.

1 Like

it doesn’t work, at this point this is impossible imo