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?
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)