Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Any suggestions on selecting a player that fits both if statements?

local function findTarget()
local target
	if script.parent.Equipped == true then
		for i, v in pairs(players) do
			if (v.Character.HumanoidRootPart.Positon - player.Chracter.HumanoidRootPart.Positon).magnitude < 50 then
				if v.Team ~= player.Team then
					if v > 1 then
					return v
				end
			end
		end
	end
end

I'm trying to make this return the player who is the target, however the issue is if there is more than one player that fits these descriptions it will return both, is there a way I can return a random player that fits both the magnitude requirement and the team requirement?

1 comment

1

Use a break

1 answer

local function findTarget()
    if script.parent.Equipped then
        for i, v in pairs(players) do
            if (v.Character.HumanoidRootPart.Positon - player.Chracter.HumanoidRootPart.Positon).Magnitude < 50 and v.Team ~= player.Team then
                return v
            end
        end
    end
end

I think this is what you are asking for.

This discussion is preserved as it was. New answers, comments, and votes are closed.