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()
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:
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!