Cant take multiple targets with magnitude

its what the title says, help

			local magn = 5
			
			for i = 1, 30 do
				for i, guy in pairs(players) do

					if guy:FindFirstChild("Humanoid") and guy:FindFirstChild("Humanoid") ~= char:FindFirstChild("Humanoid") then
						if not alreadyhit[guy.Parent] then
							if (guy.HumanoidRootPart.Position - part.Position).Magnitude < magn and guy ~= char then
								if guy then
									if guy:GetAttribute("IFrames") == false or guy:GetAttribute("InMenu") == false or guy:GetAttribute("FarmZone") == false or guy:GetAttribute("OnPose") == false then
										
										typeofdamages[wich2](player, guy, table.unpack(any))
										alreadyhit[guy.Parent] = true
									end
								end
							end
						end
					end
				end
			end
1 Like

Does players store Character models or Player objects? Because the way your script is set up it seems like players stores characters, but then what exactly is guy.Parent supposed to be?

sorry, “players”, is this local players = workspace:GetChildren()

im not gonna sugarcoat it:

			local alreadyhit = {}
			
			local char = player.Character
			local tors = char["Torso"]
			local partoz = player.Character.HumanoidRootPart

			local players = workspace:GetChildren()

			local part = Instance.new("Part",workspace.Effects)
			part.Size = sizee
			part.Color = Color3.new(1, 0, 0)
			part.Name = player.Name.. "Hitbox"
			part.Transparency = 1

			local weld = Instance.new("Motor6D")
			weld.Parent = partt
			weld.Part0 = partt
			weld.Part1 = part
			weld.Name = "joinhitbox"
			weld.C0 = cframee

			part.Anchored = false
			part.CanCollide = false
			part.CanTouch = false
			part.Parent = workspace.Effects
			part.Massless = true

			if player:WaitForChild("Data").hitboxsaw.Value == true then
				silly_Hitbox("Transparency", part, 0)
			else
				part.Transparency = 1
			end
			
			task.delay(0.5,function()

				game.Debris:AddItem(part, .0)
				game.Debris:AddItem(weld, .0)
			end)

			local magn = 5
			local targets = {}
			
			for i = 1, 30 do
				for i, guy in pairs(players) do

					if guy:FindFirstChild("Humanoid") and guy:FindFirstChild("Humanoid") ~= char:FindFirstChild("Humanoid") then
						if not alreadyhit[guy.Parent] then
							if (guy.HumanoidRootPart.Position - part.Position).Magnitude < magn and guy ~= char then
								if guy then
									if guy:GetAttribute("IFrames") == false or guy:GetAttribute("InMenu") == false or guy:GetAttribute("FarmZone") == false or guy:GetAttribute("OnPose") == false then
										
										typeofdamages[wich2](player, guy, table.unpack(any))
										alreadyhit[guy.Parent] = true
									end
								end
							end
						end
					end
				end
			end
1 Like

Okay, in that case, because every “guy” is a child of workspace, every time you do this:

guy.Parent will always be the workspace, so instead you can just do alreadyhit[guy] and make sure to change this wherever you used guy.Parent

1 Like

Because in the alreadyhit table you’d want to store every uniique person from my understanding, but if you’re just storing the workspace every time you can see how that’s not helpful.

I would recommend doing something like this so that your code is easier to understand, let me know if you have any questions.

local Players = game:GetService("Players")
local player = Players.LocalPlayer -- Replace this with something else if it's server script
local Character = player.Character
for i, guy in pairs(Players) do
    local guyCharacter = guy.Character
    if guyCharacter:FindFirstChild("Humanoid") and guyCharacter ~= Character then
        --Rest of code
    end
end
2 Likes

tbh i just fixed by myself, changing this:

			for i = 1, 30 do
				for i, guy in pairs(players) do

					if guy:FindFirstChild("Humanoid") and guy:FindFirstChild("Humanoid") ~= char:FindFirstChild("Humanoid") then
						if not alreadyhit[guy] then
							if (guy.HumanoidRootPart.Position - part.Position).Magnitude < magn and guy ~= char then
								if guy then
									if guy:GetAttribute("IFrames") == false or guy:GetAttribute("InMenu") == false or guy:GetAttribute("FarmZone") == false or guy:GetAttribute("OnPose") == false then
										typeofdamages[wich2](player, guy, table.unpack(any))
										alreadyhit[guy] = true
									end
								end
							end
						end
					end
				end
			end

literaly changing guy.Parent to guy.
still thanks
(i still dont know how did that work)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.