Attempt to access global, when I'm not trying to access a global

This is a new one to me:


Attempt to index global? What? There’s no attempt to call any globals here.

Here’s the code the error occured in:

local Bunker = script.Parent.Parent

local module = {}

function module.IsSafe(Pos)
	if not Pos then return false end
	if Bunker.Active.Value == true then
		if (Pos.X < 513 and Pos.X > 364.7 and Pos.Y < 27.6 and Pos.Y > -5.1 and Pos.Z < -337.8 and Pos.Z > -383) or Displacement.X^2 + Displacement.Z^2 < 2916 then
			local Displacement = Pos-Bunker.Shield.PrimaryPart.Position
			return true
		end
	end
	return false
end
	
return module

And here’s the code that called it:

I have never seen this before and have no idea what to do about it

It looks like you are trying to access a variable before creating it

if ... or Displacement.X^2 + Displacement.Z^2 < 2916 then <- here you are trying to use Displacement
	local Displacement = Pos-Bunker.Shield.PrimaryPart.Position <- here you create the variable
1 Like

Woops, lines in the wrong place…

…Its definitely time I got some sleep. Thanks!

2 Likes