Help kick ball game

im trying to make something like blade balls parry but its kicking instead local ball = script.Parent
local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)

local ballHighlight = ball:FindFirstChild(“Highlight”)
if not ballHighlight then
print(“No Highlight”)
end

local lastHitter = nil

local chasingColor = Color3.fromRGB(255, 0, 4)
local normalColor = Color3.fromRGB(255, 255, 255)

function setHighlightColor(color)
if ballHighlight then
ballHighlight.FillColor = color
end
end

function getRandomPlayer()
local players = Players:GetPlayers()
local maxAttempts = 10
local attempts = 0
local candidate = nil

repeat
	attempts = attempts + 1
	candidate = players[math.random(1, #players)]

	wait()

until attempts >= maxAttempts or (candidate ~= lastHitter and candidate.Character and candidate.Character:FindFirstChild("HumanoidRootPart"))

lastHitter = candidate
return candidate

end

local function moveBall()
local targetPlayer = getRandomPlayer()
local targetPosition = targetPlayer.Character and targetPlayer.Character:FindFirstChild(“HumanoidRootPart”)

if targetPosition then
	local direction = (targetPosition.Position - ball.Position).unit
	local speed = 50

	ball.Velocity = direction * speed
	setHighlightColor(chasingColor)  

	wait(1)

	setHighlightColor(normalColor)  
end

end

function onHit()
local mouse = Players.LocalPlayer:GetMouse()
local hitDirection = (ball.Position - mouse.Hit.p).unit
local hitForce = 1000

ball.Velocity = hitDirection * hitForce

local humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
	local kickAnimation = humanoid:LoadAnimation(script.KickAnimation)
	kickAnimation:Play()
end

end

ball.Touched:Connect(function(hit)
local character = hit.Parent
if character:IsA(“Model”) and character:FindFirstChild(“Humanoid”) then
moveBall()

	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		local playerHighlight = humanoid.Parent:FindFirstChild("Highlight")
		if playerHighlight then
			playerHighlight.Enabled = true
		end

		wait(2)

		if playerHighlight then
			playerHighlight.Enabled = false
		end
	end
end

end)

UserInputService.InputBegan:Connect(function(input, processed)
if not processed then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
onHit()
end
end
end)

while true do
wait(5)
moveBall()
end
code so far can someone please tell me how to make the parry so far i cant figure it out

2 Likes

I think you’re using a kick animation from this part of the script:

local kickAnimation = humanoid:LoadAnimation(script.KickAnimation)
kickAnimation:Play()

You have to change the animation to a parry animation and then make your own effects so it looks like a parry.

thats not my problem my problem is that i want to make a parry system for this but i dont know how

Is the one you have working except that it kicks instead of deflects?

yes the animation works it just kicks at the ball and the ball follows you all i need is the deflect ball system added

the ball doesnt even roll are anything it doesnt send the ball to another player it just kicks and the ball floats i want to deflect it to other players

Check if the ball is near the player in the OnHIt() function. You can use plr:DistanceFromCharacter(position: Vector). This method returns a number indicating how far the position is from the character. You can check if its near the character by checking if the value it returns is less than a number like 5 or 7.

Then move the ball if it’s inside that radius probably by multiplying the velocity by -1

ok il try it hold on il let you know if it works

local ball = script.Parent
local Players = game:GetService(“Players”)
local UserInputService = game:GetService(“UserInputService”)

local ballHighlight = ball:FindFirstChild(“Highlight”)
if not ballHighlight then
print(“No Highlight”)
end

local lastHitter = nil

local chasingColor = Color3.fromRGB(255, 0, 4)
local normalColor = Color3.fromRGB(255, 255, 255)

function setHighlightColor(color)
if ballHighlight then
ballHighlight.FillColor = color
end
end

function getRandomPlayer()
local players = Players:GetPlayers()
local maxAttempts = 10
local attempts = 0
local candidate = nil

repeat
	attempts = attempts + 1
	candidate = players[math.random(1, #players)]

	wait()

until attempts >= maxAttempts or (candidate ~= lastHitter and candidate.Character and candidate.Character:FindFirstChild("HumanoidRootPart"))

lastHitter = candidate
return candidate

end

local function moveBall()
local targetPlayer = getRandomPlayer()
local targetPosition = targetPlayer.Character and targetPlayer.Character:FindFirstChild(“HumanoidRootPart”)

if targetPosition then
	local direction = (targetPosition.Position - ball.Position).unit
	local speed = 50

	ball.Velocity = direction * speed
	setHighlightColor(chasingColor)

	wait(1)

	setHighlightColor(normalColor)
end

end

function onHit()
local mouse = Players.LocalPlayer:GetMouse()
local hitDirection = (ball.Position - mouse.Hit.p).unit
local hitForce = 1000

ball.Velocity = hitDirection * hitForce

local humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
	local kickAnimation = humanoid:LoadAnimation(script.KickAnimation)
	kickAnimation:Play()
end

end

function isBallNearPlayer(player, radius)
local character = player.Character
local humanoid = character and character:FindFirstChild(“Humanoid”)
local playerPosition = humanoid and humanoid.Parent and humanoid.Parent.PrimaryPart

if playerPosition then
	local distance = (ball.Position - playerPosition.Position).magnitude
	return distance < radius
end

return false

end

ball.Touched:Connect(function(hit)
local character = hit.Parent
if character:IsA(“Model”) and character:FindFirstChild(“Humanoid”) then
local player = Players:GetPlayerFromCharacter(character)
if player and isBallNearPlayer(player, 5) then
moveBall()
end

	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		local playerHighlight = humanoid.Parent:FindFirstChild("Highlight")
		if playerHighlight then
			playerHighlight.Enabled = true
		end

		wait(2)

		if playerHighlight then
			playerHighlight.Enabled = false
		end
	end
end

end)

UserInputService.InputBegan:Connect(function(input, processed)
if not processed then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
onHit()
end
end
end)

while true do
wait(5)
moveBall()
end
like this?

Yes I think that works

random stuff for minumum character limit asdfasdfasfasfsadf