Issue With Passing Velocity

  1. What do you want to achieve? Keep it simple and clear!
    I am adding a pass function to my soccer game. The ball is passed to any person within 180 degrees of the player, with the person with the smallest angle winning.

  2. What is the issue? Include screenshots / videos if possible!
    I can’t get the ball to go towards the player(in this case rig)
    Instead it always goes in a specific position no matter where I stand.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Searching on the devforum, checking cframe logs, experimenting (im not good with cframes)

--server
game.ReplicatedStorage.RemoteFunctions.PassFunction.OnServerInvoke = function(player, dir)
	
	if not player.Character then 
		return
	end
	if not player.Character:FindFirstChild("Ball") then
		return
	end

	BALL:WaitForChild("CanSteal").Value = false
	player.Character:WaitForChild("HumanoidRootPart"):WaitForChild("Ball"):Destroy()
	player.Character:FindFirstChild("Ball").Parent = workspace
	workspace.Ball:WaitForChild("InPossession").Value = false
	workspace.Ball:WaitForChild("PossessorName").Value = ""
	BALL.AssemblyLinearVelocity = Vector3.new(dir.X, 0, dir.Z)
	task.wait(1)
	BALL:WaitForChild("CanSteal").Value = true
end
--client
elseif inp.UserInputType == Enum.UserInputType.MouseButton2 then
		if not player.Character then
			return
		end
		if not player.Character:FindFirstChild("Ball") then
			return
		end
		
		local hRP = player.Character:WaitForChild("HumanoidRootPart")
		local closestPlayer = nil
		local closestAngle = nil
		
		
		
		local function isLookPartInFront(startPart, lookPart)
			local startPartLookVector = startPart.CFrame.LookVector
			local partDifference = (lookPart.CFrame.p - startPart.CFrame.p).Unit
			local value = math.pow((startPartLookVector - partDifference).Magnitude/2, 2)
			return value
		end
		
		for index, loopPlayer in pairs(game.Players:GetChildren()) do
			
			local value = isLookPartInFront(hRP, loopPlayer.Character:WaitForChild("HumanoidRootPart"))
			if value <= 0.5 and loopPlayer ~= player then
				if closestAngle then
					if value < closestAngle then
						closestAngle = value
						closestPlayer = loopPlayer
					end
				else
					closestAngle = value
					closestPlayer = loopPlayer
				end
			end
		end
		
		closestAngle = 69
		closestPlayer = workspace.Rig
		if closestAngle and closestPlayer then
			--local cFrame = CFrame.lookAt(hRP.Position, closestPlayer.Character:WaitForChild("HumanoidRootPart").Position)
			local cFrame = CFrame.lookAt(hRP.Position, closestPlayer:WaitForChild("HumanoidRootPart").Position)
			      
			game.ReplicatedStorage.RemoteFunctions.PassFunction:InvokeServer(cFrame)
		end
	end
end)

fixed it, i set the velocity of the ball to the position of (selected players hrp - player hrp).Unit * speed

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.