You don’t need connection
variable and then manually :Disconnect()
… That’s literally the point of :Once()
, it self-disconnects.
The problem is that break
works only if it is in the first if
block. So, you will need to rework your script to be
...
for _, body_part in pairs(Character:GetDescendants()) do
if body_part:IsA("BasePart") then
inputted = true
body_part.Touched:Once(function(hit_part)
local Humanoid = hit_part.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
local HumanoidRootPart = hit_part.Parent:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
local Direction = (HumanoidRootPart.Position - body_part.Position).Unit
Remote:FireServer(Direction, HumanoidRootPart)
wait(1)
debounce = false --------------
end
end
end)
end
if inputted then
break
end
end
You are still doing all the calculations on LocalScript
. Bad idea.