I have a soccer ball system, it uses contextActionService to detect input, when the player presses the input key, then it sets a “kicking” variable to true (actionTriggered
), after the variable is set to true, when the player’s leg touches a ball it will apply force. The task.delay(.2) acts as a kicking duration, but for some reason, no matter how low I set the kicking duration (or kicking cooldown), it seems like there is a built in cooldown? Like it only lets me hit the ball every .5 seconds for some reason?
local function dribble(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if actionName ~= "Dribble" then
return
end
if ToolController:isUsing() then -- Prevents from using other things while kicking
return
end
if inputState == Enum.UserInputState.Begin then
torso.CollisionGroup = "Character" -- This makes the touch detection more accurate
actionTriggered = true
ToolController:setUsing(true)
task.delay(.2, function()
torso.CollisionGroup = "Default"
actionTriggered = false
ToolController:setUsing(false)
end)
end
end
local function onEquipped(mouse: Mouse)
ContextActionService:BindAction("Dribble", dribble, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch)
end
local function onUnequipped(...)
ContextActionService:UnbindAction("Dribble")
end
local function onTouched(otherPart: BasePart, leg: string)
if not otherPart:HasTag("Ball") then
return
end
if ToolController:getCurrentLeg() ~= leg.Name then
return
end
if not actionTriggered then
return
end
actionTriggered = false
ReplicatedStorage.Remotes.SetNetworkOwner:FireServer(otherPart) -- Tell the server to make us the 'NetworkOwner' of the ball
local reactVelocity = Instance.new("BodyVelocity")
reactVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
reactVelocity.Velocity = humanoidRootPart.CFrame.LookVector * 22
reactVelocity.Parent = otherPart
Debris:AddItem(reactVelocity, .3)
end