Metatable problem

Practicing metatable right now. and i ran into a problem.

It errors :
15:51:23.202 - Workspace.Script:1: Attempt to modify a readonly table

i already have a table set?

i dont know why it does that could someone help me please

math.random = {}
math.random._index = math.random
val = val or 0
function math.random:newnumber(val)
	local self = setmetatable({},math.random)
	self(val)
end

math.random:newnumber(100)
1 Like

Im trying to make it so it prints a random number from the value given

The math table is readonly. What are you really wanting to do with this?

whoops sorry about that…

You could just create simple function to do this. No need for a fancy meta table

I don’t like attach metatables with lua function (example: math.random, math,rad, math.deg).

As i said im practicing metatables since i think they’re cool.