Script returning error: "attempt to call a table value" from a table?

hi!!

i’ve made a script which is supposed to find the objects inside of a folder, then pick them at random
on line 3 of this code, it always returns the error “attempt to call a table value” despite it calling a value from a table. im definitely doing something wrong, so i would appreciate some help, thanks!

local trinkets = game.ServerStorage.Cloneables:GetChildren()
local trinketspawns = script.Parent.TrinketSpawns:GetChildren()
local randomtr = trinketspawns()[math.random(1,#trinketspawns())]
local randomtrC = game.ServerStorage.Cloneables:GetChildren()
local randomtrC1 = randomtrC()[math.random(1,#randomtrC())]

local function spawnathing()
		print(randomtr)
		randomtrC1:Clone()
		randomtrC1.Position = randomtr.Position
	end


task.wait(2)
spawnathing()

local randomtr = trinketspawns[math.random(1,#trinketspawns)]
local randomtrc1 = randomtrC[math.random(1,#randomtrC)]

Change both of these to this and it should work

1 Like

remove the brackets () at the end, that’s calling the table

local randomtr = trinketspawns[math.random(1,#trinketspawns)]
1 Like

okay, i will give this a try. thank you!

The reason why it says that error by the way is because it thinks you’re using a method/function when it doesn’t exist.

For example, you call a function so that it runs by writing it like this:

local function DoSomething()
print("hi")
end

DoSomething()

Same with a method:

local part = workspace.Part

part:Clone()

Both of these are categorized as “calling” in lua, but obviously you can only call with methods and functions. Table values cannot be called. You can’t just do:

local t = {1, 2, 3}

t()
1 Like

hey!
i appreciate the knowledge here, i will definitely be saving that for later,
but using the couple of lines you gave me previously, i managed to achieve the functionality of the script that i was looking for. i really appreciate the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.