Help making a soccerball

local Ball = workspace:WaitForChild("Ball")
local Velocity = 250
local debounce = false

Ball.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		if debounce then return end
		debounce = true
		local Direction = hit.Parent:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Velocity
		Ball:ApplyImpulse(Direction)
		wait(2)
		debounce = false
	end
end)

Why does it not register the first time you touch the ball?

1 Like

If the humanoid has an accessory and this touches the ball, then the parent of the touched part won’t be the character.

You can check this by printing the “hit” and seeing what was touched.

Also you dont check for a false debounce, i would add it in on the line:

if hit and hit.Parent:FindFirstChild(“Humanoid”) and not debounce then

2 Likes

This is a better way of detecting if the object touching the ball is a player and this may help:

local Ball = workspace.Ball

local Velocity = 250

local Debounce = false

Ball.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if Player and not Debounce then
        local Character = Player.Character
        local HumanoidRootPart = Character.HumanoidRootPart
        local Direction = (HumanoidRootPart.CFrame.LookVector) * Velocity

        Debounce = true
        Ball:ApplyImpulse(Direction)
        task.wait(2)
        Debounce = false
    end
end)
1 Like