You can't use NumPy in Roblox Studio. Roblox Studio runs **Luau** scripts and NumPy is a **Python** library, so import numpy will never work inside a Roblox script. For NumPy-style math in your game, use Luau's built-in vector and math libraries, CFrame, a community matrix library, or your own Python server that your game calls with HttpService.
What each one is
These two show up in the same search, but they do different jobs.
- Roblox Studio is the editor for Roblox games. Its scripts are written in Luau, a language derived from Lua 5.1.
- NumPy is a Python library for fast math on big arrays of numbers, including linear algebra, statistics and random simulation.
Roblox only runs Luau, so Python libraries can't be loaded. To see how Luau differs from plain Lua, read Lua vs Luau and why AI code breaks in Studio.
Heads up: the PyPI package called roblox-studio (ro.py-studio) is a Python library for interacting with Roblox installations on your computer. It does not let you run Python in your game.What Luau gives you out of the box
Luau's standard library has a math library (with functions like clamp, lerp, map, noise, round and sign) and a vector library (with create, magnitude, normalize, cross, dot, angle and more). It does not have a built-in matrix or ndarray type. There is a DevForum feature request asking Roblox to add one.
For most game math, the built-ins are enough:
local a = vector.create(1, 0, 0)
local b = vector.create(0, 1, 0)
print(vector.dot(a, b)) -- 0
print(vector.cross(a, b)) -- 0, 0, 1
print(vector.magnitude(vector.create(3, 4, 0))) -- 5
print(vector.normalize(vector.create(10, 0, 0))) -- 1, 0, 0
-- Same dot product in the Vector3 style most tutorials use
print(Vector3.new(1, 0, 0):Dot(Vector3.new(0, 1, 0))) -- 0
print(math.lerp(0, 10, 0.25)) -- 2.5
print(math.clamp(15, 0, 10)) -- 10In Roblox, vector.create gives you a Vector3, so you can mix both styles. Vector3 also has :Cross(), .Magnitude and .Unit.
Use CFrame for rotations and 3D transforms
If you were thinking of NumPy for rotation matrices, Roblox already has one built in. A CFrame stores a 3x3 rotation matrix plus a position. One of its constructors takes all 12 numbers directly: x, y, z for the position, then R00 through R22 for the 3x3 rotation. It also has Position and Rotation properties.
-- Position (0, 5, 0) with an identity rotation, written out as a matrix
local cf = CFrame.new(0, 5, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
-- Turn it 90 degrees around the Y axis
local turned = cf * CFrame.Angles(0, math.rad(90), 0)
print(turned.Position) -- 0, 5, 0
print(turned:PointToWorldSpace(Vector3.new(1, 0, 0))) -- about 0, 5, -1The second result is *about* 0, 5, -1 because of floating point rounding.
Doing general matrix math in Luau
For matrices of any size, you can write the math yourself or use a community library.
Write it yourself
A matrix can be a table of rows. Here is matrix multiplication, the same thing NumPy does with a @ b:
local function matMul(a, b)
local result = {}
for i = 1, #a do
result[i] = {}
for j = 1, #b[1] do
local sum = 0
for k = 1, #b do
sum += a[i][k] * b[k][j]
end
result[i][j] = sum
end
end
return result
end
local m = matMul({ { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } })
print(m[1][1], m[1][2], m[2][1], m[2][2]) -- 19 22 43 50Use a community library
These DevForum libraries are ModuleScripts you add to your game and require():
- [NuMath](https://devforum.roblox.com/t/numath-a-better-math-library/3193438) (Oct 2024). Matrix add, subtract, multiply, transpose, inverse, determinant, eigenvalues and eigenvectors, plus LU and SVD decomposition.
- **[Linear Algebra Library](https://devforum.roblox.com/t/linear-algebra-library/241276)** by NoahWillCode (Feb 2019). The author says: "For those of you who have used Python before, the syntax in this library often resembles that of numpy." It supports matrices and vectors of any size,
A.Shape, arithmetic operators, transpose, norms, dot products, projection and Gram-Schmidt. Sparse matrices and SVD were listed as planned. It's older, so test it in your place first. - **[mathsm](https://devforum.roblox.com/t/mathsm-extensible-math-library-vectors-matrices-transformations/3852274)**. Vectors, matrices and transformations. Its author notes that Roblox's built-in
Vector2andVector3are faster because they are implemented in C++, though mathsm vectors offer more features. For speed-sensitive vector math, stick with the built-ins.
The NuMath author's example names the ModuleScript NUMATH and keeps it in ServerScriptService. Use the exact name of the ModuleScript in your place, or you will get a "not a valid member" error:
local ServerScriptService = game:GetService("ServerScriptService")
local NuMath = require(ServerScriptService.NUMATH)Check each library's DevForum post for its exact function names.
If you really need Python and NumPy
Sometimes you want real NumPy, for example to analyze game data. In that case, run Python on your own external server and have your game talk to it over HTTP.
1. In Studio, go to **File > Experience Settings > Security** and turn on **Allow HTTP Requests**. HTTP calls are off by default. 2. Use HttpService (GetAsync, PostAsync or RequestAsync) from a server Script, for example in ServerScriptService. HTTP requests can't be sent from LocalScripts, so pass results to players with RemoteEvents. 3. Stay under 500 HTTP requests per minute per game server. Open Cloud requests have a separate limit of 2,500 per minute.
Here is a small Python server using Flask and NumPy. It takes a list of numbers and returns the mean and standard deviation:
from flask import Flask, request, jsonify, abort
import numpy as np
app = Flask(__name__)
API_KEY = "change-me"
@app.post("/compute")
def compute():
if request.headers.get("X-Api-Key") != API_KEY:
abort(401)
values = np.array(request.get_json()["values"], dtype=float)
return jsonify(mean=float(values.mean()), std=float(values.std()))The server has to be deployed to a public HTTPS host. A localhost address won't work from a live game. The X-Api-Key check stops random people from using your endpoint, so change change-me to your own secret.
The Roblox side:
-- Script in ServerScriptService
local HttpService = game:GetService("HttpService")
local URL = "https://your-server.example.com/compute"
local ok, response = pcall(function()
return HttpService:RequestAsync({
Url = URL,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
["X-Api-Key"] = "change-me",
},
Body = HttpService:JSONEncode({ values = { 1, 2, 3, 4 } }),
})
end)
if ok and response.Success then
local data = HttpService:JSONDecode(response.Body)
print(data.mean) -- 2.5
else
warn("Request failed:", ok and response.StatusCode or response)
endWhere Picoo fits
If you want help writing the Luau side of this, like the matrix code or the HttpService script above, Picoo is a Roblox Studio AI plugin that writes Luau. It does not write Python or NumPy code for you. It writes Server Scripts, LocalScripts and ModuleScripts, and one prompt can produce server, client and module code together. It reads your live Studio hierarchy with each prompt and captures errors from the Output console. Before a script goes into your place, it runs a parse check with the real Luau compiler. That confirms Studio can load the script, but it does not prove your game logic is right. Picoo is a premium-only paid tool: Pro is $19/mo or $12/mo billed yearly (200 credits/month). If you are comparing Studio tools, see Roblox Assistant vs Picoo.
FAQ
Can I use Python in Roblox Studio?
No. Roblox Studio runs Luau. You can only use Python on an outside server that your game contacts through HttpService from a server Script, after you turn on Allow HTTP Requests.
Is there a NumPy for Roblox?
There is no official one. Community libraries come close: NuMath covers inverse, determinant, eigenvalues and SVD, and the Linear Algebra Library says its syntax often resembles NumPy.
Is the roblox-studio package on PyPI the real Roblox Studio?
No. It is ro.py-studio, a Python library for interacting with Roblox installations on your computer. It has nothing to do with NumPy or running Python in games.
Do I need Python to save player data?
No. Roblox saves player data with DataStores, which you write in Luau. See how to make a Roblox DataStore.