I was kind of messing around with my soccer system trying to find ways that dont use .touched, I tried something like this where it starts a renderSteppedConnection to check for the ball while the player is kicking the ball. Im not sure if this would lower performance, or it might even have worse performance than .touched? I dont know any other ways to constantly check if my leg is touching the ball besides using a loop like RunService
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local tool = script.Parent
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local torso = character:WaitForChild("Torso")
local rightLeg = character:WaitForChild("Right Leg")
local leftLeg = character:WaitForChild("Left Leg")
local actionTriggered = false
local renderSteppedConn: RBXScriptConnection
local function dribble(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject): ()
if actionName ~= "Dribble" then
return
end
if inputState == Enum.UserInputState.Begin then
if actionTriggered then
return
end
torso.CollisionGroup = "Character"
actionTriggered = true
renderSteppedConn = RunService.RenderStepped:Connect(function(deltaTime: number)
local partsInPart = Workspace:GetPartsInPart(rightLeg)
for index, part in ipairs(partsInPart) do
if part:HasTag("Ball") then
actionTriggered = false
ReplicatedStorage.Remotes.SetNetworkOwner:FireServer(part)
local react = Instance.new("BodyVelocity")
react.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
react.Velocity = humanoidRootPart.CFrame.LookVector * 22
react.Parent = part
Debris:AddItem(react, .3)
renderSteppedConn:Disconnect()
end
end
end)
task.delay(.5, function()
torso.CollisionGroup = "Default"
actionTriggered = false
renderSteppedConn:Disconnect()
end)
end
end
local function onEquipped(mouse: Mouse): ()
ContextActionService:BindAction("Dribble", dribble, true, Enum.UserInputType.MouseButton1)
end
local function onUnequipped(): ()
ContextActionService:UnbindAction("Dribble")
end
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)