Hey! I’m trying to make a wand be used as a melee weapon or ranged weapon depending on how close you are to an enemy.
My problem is that the script checks for humanoids, but only focuses on one not regarding any other humanoids in the area. If anyone could help me with this I would be very thankful.
Here is my issue
Code:
for _, humanoids in pairs(game.Workspace:GetDescendants()) do
if humanoids:IsA("Humanoid") and humanoids ~= plr.Character:FindFirstChild("Humanoid") then
local target = humanoids:FindFirstAncestorOfClass("Model")
if target and target ~= plr.Character then
if target.PrimaryPart or target:FindFirstChild("Humanoid") then
local distance = (plr.Character.HumanoidRootPart.Position - target:FindFirstChild("HumanoidRootPart").Position).magnitude
if distance <= 10 then
return "MeleeRange"
else
return "CastRange"
end
end
end
end
end