The chunk is most likely not loaded. Try this:
It will ensure that the chunks are loaded and then get the height.
Btw, I didn't test this code. There might be a syntax error in it.
local X = math.random(-2000, 2000)
local Z = math.random(-2000, 2000)
local _, Height
local World = Player:GetWorld()
World:ChunkStay({math.floor(X / 16), math.floor(Z / 16)}, nil,
function()
_, Height = World:TryGetHeight(X, Z)
end
)
It will ensure that the chunks are loaded and then get the height.
Btw, I didn't test this code. There might be a syntax error in it.

