I have a problem where when a player / npc is added, you can’t hit them.
Is this a problem with ROBLOX, or a problem with my code?
for _, v in pairs(game.Workspace:GetDescendants()) do
if v:FindFirstChild("Humanoid") then
if v:FindFirstChild("Head") then
if v == tool.Parent then return end
local magnitude = (v.Head.Position-tool.Parent.Head.Position).magnitude
if magnitude < radius then
local directionVector = (v.HumanoidRootPart.CFrame.p - tool.Parent.HumanoidRootPart.Position).unit
local velocity = directionVector * 75
if math.random(1,1) == 1 then
--v.Ragdoll.Tripped.Value = true -- don't want fists to trip do u?
end
v.HumanoidRootPart.Velocity = velocity
v.Humanoid:TakeDamage(dmg)
critfunc(critchance,v)
pickrandomsound(tool.Handle.Hits,tool.Handle)
gibs(v)
end
end
end
end
Then try limiting where the script is looking for the NPCs. If you put them into a Folder in the Workspace then it’d only only search game.Workspace.(Name of Folder):GetDescendants()