The person who blocks the ball will be targeted once more

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 don’t want to target the person who blocks the ball again

  2. What is the issue? Include screenshots / videos if possible!
    It matches the title.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried web surfing and fixing it by myself for 3 hours, but it hasn’t been fixed at all

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function BallService:FindNearestPlr(plr)
	local Character = plr.Character
	if not Character or not Character:FindFirstChild("Head") then return end

	local bestMatch
	local greatestDot = 0
	local shortestDistance = math.huge

	for _, v in ipairs(Players:GetPlayers()) do
		if v ~= plr and v ~= self.TargetPlayer and table.find(RoundService.ActivePlayers, v) and v.Character and v.Character:FindFirstChild("Head") then
			local characterToEnemy = (v.Character.Head.Position - Character.Head.Position).Unit
			local plrLook = Character.Head.CFrame.LookVector

			local dotProduct = characterToEnemy:Dot(plrLook)

			if dotProduct > .5 then
				if dotProduct > greatestDot then
					greatestDot = dotProduct
					bestMatch = v
				end
			end
		end
	end

	if not bestMatch then
		for _, player in ipairs(Players:GetPlayers()) do
			if player ~= plr and player ~= self.TargetPlayer and table.find(RoundService.ActivePlayers, player) and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
				local distance = (player.Character.HumanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).Magnitude

				if distance < shortestDistance then
					shortestDistance = distance
					bestMatch = player
				end
			end
		end
	end

	return bestMatch
end

function BallService:FindRandomPlayer()
	local validPlayers = {}

	for _, player in ipairs(Players:GetPlayers()) do
		if table.find(RoundService.ActivePlayers, player) then
			table.insert(validPlayers, player)
		end
	end

	if #validPlayers > 1 then
		local RngNumber = math.random(1, #validPlayers)
		local newTargetPlayer = validPlayers[RngNumber]

		self.PreviousTargetPlayer = self.TargetPlayer
		self.TargetPlayer = newTargetPlayer

		self:HighlightPlr()
	end
end

function BallService:SpawnBall()
	if self.BallSpawned then return end

	self:Reset()
	self:FindRandomPlayer()

	if not self.TargetPlayer or not RoundService._gameActive then
		self:Reset()
		return
	end

	local randomName = tostring(math.random(1, 999))

	self.RealBall = BallTemplate:Clone()
	self.RealBall.Name = randomName
	self.RealBall.Position = RoundService.SelectedMap.BALLSPAWN.Offset.WorldCFrame.Position
	self.RealBall.Parent = workspace.Balls
	self.RealBall.Transparency = 1

	self.FakeBall = FakeBallTemplate:Clone()
	self.FakeBall.Name = randomName
	self.FakeBall.Position = RoundService.SelectedMap.BALLSPAWN.Offset.WorldCFrame.Position
	self.FakeBall.Parent = workspace.Balls

	self.RealBall:SetNetworkOwner(nil)
	self.FakeBall:SetNetworkOwner(nil)

	self.BallSpawned = true
	self.IsReset = false

	self.RealBall.Touched:Connect(function(hit)
		self:HandleBallTouched(hit)
	end)
end

function BallService:HandleBallHit()
	local player = self.TargetPlayer
	if not player then return end

	local isParried = ParryService:GetParryState(player)
	if not isParried then
		print("Player", player.Name, "was hit and is not parrying.")
		player.Character.Humanoid.Health = 0
		if not table.find(self.DeadPlayers, player) then
			table.insert(self.DeadPlayers, player)
		end
		self:Reset()

		if self.PreviousTargetPlayer then
			self.Client.SendElims:Fire(self.PreviousTargetPlayer, player)
			self.PreviousTargetPlayer:FindFirstChild("leaderstats"):FindFirstChild("💀 Elims").Value += 1
		end

		if RoundService._gameActive then
			task.wait(0.5)
			self:SpawnBall()
		end
	else
		print("Ball hit was prevented due to parry state for player", player.Name)
	end
end

function BallService:HandleBallBlock()
	local player = self.TargetPlayer
	if not player then return end

	if ParryService:GetParryState(player) then
		self.CSpeed = self.CSpeed + 0.1

		self.ParrySuccess:Fire(player)
		self:PlayParryEffects(player)

		local nearestPlayer = self:FindNearestPlr(player)
		if nearestPlayer then
			if nearestPlayer == player then
				print("Nearest player is the same as the current target player. Skipping redirection.")
				return
			end

			self.PreviousTargetPlayer = self.TargetPlayer
			self.TargetPlayer = nearestPlayer
			self:HighlightPlr()

			local lookVector = player.Character:FindFirstChild("LookVector").Value
			local PointA = self.RealBall.Position
			local PointC = nearestPlayer.Character.HumanoidRootPart.Position
			local curveStrength = math.min(self.MaxCurveStrength, (PointC - PointA).Magnitude / 2)
			local PointB = PointA + lookVector * curveStrength

			print("Ball Blocked!")
			print("Current Target Player:", self.TargetPlayer.Name)
			print("Nearest Player:", nearestPlayer.Name)
			print("Curve Strength:", curveStrength)
			print("Curve Points: PointA", PointA, "PointB", PointB, "PointC", PointC)

			self.IsCurving = true
			self.CurveStartTime = tick()
			self.CurveDuration = calculateCurveDuration(self.CSpeed)
			self.CurveMinY = PointA.Y
			self.CurvePointB = PointB
			self.CurvePointC = PointC

		else
			print("No valid target player found for redirection after block")
		end
	else
		print("Ball block was attempted but no parry state was found for player", player.Name)
	end
end

It’s not a full script, but I will give it to you if you need

store the previous player in a variable and check in the loop if it was that player. Simply pass them if it is.

I would just do a repeat loop until the target character was not the previous touched character.

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