Attachement script

Im making a script that when a player touches a soccer ball, it gets attached to them and moves with the player until they press the kick button.

My problem is that the when a player touches the ball, it gets attached directly on the foot.
eeeeeeeeee

Ive been trying too make it go in front of the player, but i cant make it work.

eeeeeeeee2

If you know how to fix this, i would appreciate it if you hellped.Here is the script (it goes in the ball, thats in workspace)

local ball = script.Parent
local attached = false
local speeding = false

speed = 25

script.Parent.Touched:Connect(function(hit)
	if attached == false then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if hit.Name == "RightFoot" or hit.Name == "LeftFoot" then
				attached = true
				ball.Parent = hit
				ball.CFrame = hit.CFrame * CFrame.new(0,0, -3) --- HERES THE LINES IM TALKING ABOUT

				for i, v in pairs(hit:GetChildren()) do
					if v:IsA("Motor6D") then
						local newV = v:Clone()
						newV.Parent = ball
						newV.Part0 = ball
						newV.Part1 = ball.Parent
					end
				end
			end
			plr.PlayerGui:WaitForChild("ScreenGui").Shoot.Visible = true
		end
	end
end)

game.ReplicatedStorage.ShootBall.OnServerEvent:Connect(function(plr)
	if attached == true then
		if ball.Parent.Name == "RightFoot" then
			ball.RightAnkle:Destroy()
		elseif ball.Parent.Name == "LeftFoot" then
			ball.LeftAnkle:Destroy()
		end
		
		ball.Parent = workspace
		ball.CanTouch = false
		ball.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * speed
	
		speeding = true
		wait(0.5)
		ball.CanTouch = true
		plr.PlayerGui:WaitForChild("ScreenGui").Shoot.Visible = false
		attached = false
	end
end)

while wait(.1) do
	if speeding == true then
		ball.Velocity += Vector3.new(1,0,0)
	end
	if ball.Velocity.X > 0 or ball.Velocity.Z > 0 then
		speeding = false
	end
end
2 Likes