I’m trying to make a script where it detects any character in a 20 (stud?) radius. So far it’s not detecting my dummy and i have no idea why
local tool = script.Parent
local debounce = false
tool.Shot.OnServerEvent:Connect(function(plr, mousePos)
if not debounce then
debounce = true
local function FindNearestTargets()
local targets = {}
local workspaceStuff = workspace:GetChildren()
for i, thing in workspaceStuff do
local hum = thing:FindFirstChild("Humanoid")
if hum then
local dis = (plr.Character.HumanoidRootPart.Position - thing.HumanoidRootPart.Position).Magnitude
if dis <= 20 then
table.insert(targets, thing)
end
end
end
end
local target = FindNearestTargets()
if target then
print(target.Name)
target.Humanoid:TakeDamage(30)
end
task.wait(1)
debounce = false
end
end)