I have a dribbling script and for some reason, there is a cooldown on my dribbles. You may think this is because of the isKicking value, but no matter how low I set the cooldown for that, it doesn’t affect anything? It’s like there is some built in cooldown preventing me from kicking the ball really fast. I have seen other games that do not have this sort of issue.
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local FORCE_LIFETIME = .3
local FORCE_MULTIPLIER = 15
local modules = ReplicatedStorage.Modules
local ToolController = require(modules.ToolController)
local tool = script.Parent
local animations = tool:WaitForChild("Animations")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")
local torso = character:WaitForChild("Torso")
local rightArm = character:WaitForChild("Right Arm")
local leftArm = character:WaitForChild("Left Arm")
local rightLeg = character:WaitForChild("Right Leg")
local leftLeg = character:WaitForChild("Left Leg")
local dribbleAnimation = animations:WaitForChild("Dribble2")
local dribbleAnimationTrack: AnimationTrack = humanoid.Animator:LoadAnimation(dribbleAnimation)
local expectingInput = false
local isKicking = false
tool.Equipped:Connect(function(mouse: Mouse)
expectingInput = true
end)
tool.Unequipped:Connect(function()
expectingInput = false
end)
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent or not expectingInput then
return
end
if input.KeyCode == Enum.KeyCode.R then
print("Pressing")
isKicking = true
torso.CollisionGroup = "IgnoreBall"
dribbleAnimationTrack:Play(0)
task.delay(.05, function()
isKicking = false
torso.CollisionGroup = "Default"
dribbleAnimationTrack:Stop(0)
end)
end
end)
rightLeg.Touched:Connect(function(otherPart: BasePart)
if otherPart.Name ~= "Ball" then
return
end
if not isKicking then
return
end
if ToolController:getCurrentLeg() ~= "Right" then
return
end
isKicking = false
ReplicatedStorage.Remotes.SetNetworkOwner:FireServer(otherPart)
local reactVelocity = Instance.new("BodyVelocity")
reactVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
reactVelocity.Velocity = -humanoidRootPart.CFrame.RightVector * FORCE_MULTIPLIER + humanoidRootPart.CFrame.LookVector * (FORCE_MULTIPLIER * .5)
reactVelocity.Parent = otherPart
Debris:AddItem(reactVelocity, FORCE_LIFETIME)
end)
leftLeg.Touched:Connect(function(otherPart: BasePart)
if otherPart.Name ~= "Ball" then
return
end
if not isKicking then
return
end
if ToolController:getCurrentLeg() ~= "Left" then
return
end
isKicking = false
ReplicatedStorage.Remotes.SetNetworkOwner:FireServer(otherPart)
local reactVelocity = Instance.new("BodyVelocity")
reactVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
reactVelocity.Velocity = -humanoidRootPart.CFrame.RightVector * FORCE_MULTIPLIER + humanoidRootPart.CFrame.LookVector * (FORCE_MULTIPLIER * .5)
reactVelocity.Parent = otherPart
Debris:AddItem(reactVelocity, FORCE_LIFETIME)
end)