Modulescript function wrongly passing values

I used a modulescript to handle my npc pathfinding, although randomly an unintended thing happened.

image
poop,1000,{} and attackers are values intended to be input. The modulescript table isn’t.

The first parameter of the function suddenly turned into a table, here is the modulescript:

module.UpdateTarget = function(npc,range,unabletotargettable,allyteam,isranged)
	local target = nil
	local lowestdistance = range	
	print(npc,range,unabletotargettable,allyteam,isranged)
	local function rangedunabletotarget(instancechecked) -- instancechecked = the model itself
		local ignore = false
		if isranged == true then
			ignore = true
		else
			if table.find(unabletotargettable,instancechecked) then
				ignore = nil
			else
				ignore = true
			end		
		end
		return ignore
	end

the code below calls the modulescript function with the parameters.

if time() - lastretarget > 0.5 then -- finds target
			lastretarget = time()
			lastfoundtarget = target
			target = npcmodulescript.UpdateTarget(npc,sightrange,unabletotargettable,allyteam,ranged)
		end

npc isn’t reassigned anywhere in the script, as well as sightrange. unabletotargettable is only a table and never reassigned to anything else. Allyteam is only assigned when the script runs and the ranged boolean never reassigns. Yet the “npc” part of the modulescript turns into a table. Is there any reason for this (also I’m new to modulescripts)?

1 Like