Soccer ball acting very weird

Sometimes my soccer ball doesnt move even though it says the force was applied???
Code:

local function onTouched(hitPart: BasePart)
	if hitPart.Name ~= "Ball" or not isKicking then
		return
	end
	ToolManager:setNetworkOwner(hitPart)
	
	hitPart:ApplyImpulse(humanoidRootPart.CFrame.LookVector * power + humanoidRootPart.CFrame.UpVector * height)
	print("applied")
	local ballPosition = hitPart.Position + Vector3.new(0, humanoidRootPart.Position.Y - hitPart.Position.Y, 0)
	local dotProduct = humanoidRootPart.CFrame.LookVector:Dot(ballPosition - humanoidRootPart.Position)
	local torsoOrientation = math.acos(dotProduct / (ballPosition - humanoidRootPart.Position).Magnitude)
	
	if torsoOrientation > math.rad(18) and (hitPart.Position - leftArm.Position).Magnitude < (hitPart.Position - rightArm.Position).Magnitude then
		task.spawn(function()
			for curveAmount = 1, power * .3 do
				hitPart:ApplyImpulse(-humanoidRootPart.CFrame.RightVector) -- Apply curve movement
				task.wait()
			end
		end)
		hitPart:ApplyAngularImpulse(Vector3.new(0, .3 * power, 0)) -- Apply spin to the ball
	elseif torsoOrientation > math.rad(45) and (hitPart.Position - rightArm.Position).Magnitude < (hitPart.Position - leftArm.Position).Magnitude then
	task.spawn(function()
		for curveAmount = 1, power * .3 do
			hitPart:ApplyImpulse(humanoidRootPart.CFrame.RightVector) -- Apply curve movement
			task.wait()
		end
	end)
	hitPart:ApplyAngularImpulse(Vector3.new(0, .3 * -power, 0)) -- Apply spin to the ball
	end
	isKicking = false
	resetPower()
end

’
https://gyazo.com/ba95cf466ac3298f461a45dd2ab81cf8

Please watch this video, it will show what I mean.

1 Like

When including a custom method that’s outside the scope you’re providing us, you can at least provide a comment of what it’s doing. I’m assuming this is a wrapper to the BasePart:SetNetworkOwner, yet, that method only accepts either nil or a Player.
Assuming you’re setting the ball part’s network ownership to the player kicking it, and that this script is server sided: the client is telling the server where the ball is position-wise, preventing the server’s influence like ApplyImpulse()

1 Like
function ToolManager:setNetworkOwner(ball)
	events.SetNetworkOwner:FireServer(ball)
end

Module Script ^^^

events.SetNetworkOwner.OnServerEvent:Connect(function(player, ball)
	ball:SetNetworkOwner(player)
end)

Server script ^^^

This whole shoot script is handled on the client, I simply use a module that fires an event to set network owner to the player who “touched” (kicked) the ball. That “toolmanager” module is only being accessed on the client.

1 Like