This has happened to me more than once to simple and complex scripts for reasons i do not know.

I have a script trying to call a function and i get an error trying to call the function.

Workspace.Script:8: attempt to call global 'createMap' (a nil value)

I do not know why this is happening. Here is the code.

	math.randomseed(tick())
	local Seed = math.random(0,999999)
	local MaxTest = {}
	local MinTest = {}
	local Max = 0
	local Min = 0
	
	createMap(50,50,10,10,5,2.5)

 function createMap(Width, Height, Scale, Octives, Persistance, Lacunarity)
	local cordX = {}
	for x = 0,127 do
		local cordY = {}
  		cordX[x] = cordY
		for y = 0,127 do
			local Amplitude = 1
			local Frequency = 1
			local noiseHeight = 0		
		
			for i=0, Octives do
				local SampleX = x/Scale * Frequency
				local SampleY = y/Scale * Frequency
		
				local PerlinValue = math.noise(SampleX,SampleY)
				noiseHeight = noiseHeight + PerlinValue * Amplitude
				Amplitude = Amplitude * Persistance
				Frequency = Frequency * Lacunarity
			end
			cordY[y] = noiseHeight
		end
		table.insert(MaxTest,1,math.max(unpack(cordX[x])))
		table.insert(MinTest,1,math.min(unpack(cordX[x])))
		wait()
	end
	Max = math.max(unpack(MaxTest))
	Min = math.max(unpack(MinTest))
end

2 comments

0

I am going to answer my own question here. I found out in lua you need to call the function after you declare it or the script will not notice it and find it a nil value.

0

Try to call the function after you have defined it. In Lua, you have to define the function before you call it.