Can't find an error on my code!

Hello!
As you can see, i’m basically, checking if the Interaction name is ‘Police’ (interaction would be a part)
OtherInteractions is collection service tagged objects
For some reason when the name of ‘v’ is not “Police” still, doesn’t works or returns the ‘v’
I don’t think there’s an error?
The allowed teams is a Table with objects of the player tam, the ‘V’ name is ‘ClickDetection’

:thinking:

local function FindNearestOtherInteraction()
	if player.Character then
		if (not player.Character.Humanoid.Sit) and (player:WaitForChild('Interaction').Pinned.Value == false) and (player:WaitForChild('Interaction').Grabbing.Value == "") then
			for i,v in ipairs(OtherInteractions) do
				if player:DistanceFromCharacter(v.Position) <= 7 then
					if v.Name == 'Police' then
						if table.find(AllowedTeams, Player.Team) then
					currentother = v
						return v
end
					end
				
					if v.Name ~= 'Police' then
								currentother = v
					return v
					
					end
				end
			end
		end
	end
	lastother = nil
	currentother = nil
	return nil
end

You return v when the Name isn’t Police. I’m not sure why you think it’s a bug when you specifically programmed it that way.

2 Likes

That’s exactly what is it meant to do, if the name isn’t police, it returns, but, it doesn’t returns, lol

Then the player is probably over 7 studs away.

2 Likes