Attempt to call a table value

so, I’m maknig a Ui library and the initializer script for it is quite similar to RoAct, but I keep getting an error “Attempt to call a table value”

local src = script.Basic
local srcActions = script.Actions

local Pollen = {
	alignElement = require(src.alignElement),
	createElement = require(src.createElement),
	createTween = require(srcActions.createTween),
	render = require(src.Render),
}

return Pollen

for comparison, this is RoAct’s initializer

--~strict
--[[
	Packages up the internals of Roact and exposes a public API for it.
]]

local GlobalConfig = require(script.GlobalConfig)
local createReconciler = require(script.createReconciler)
local createReconcilerCompat = require(script.createReconcilerCompat)
local RobloxRenderer = require(script.RobloxRenderer)
local strict = require(script.strict)
local Binding = require(script.Binding)

local robloxReconciler = createReconciler(RobloxRenderer)
local reconcilerCompat = createReconcilerCompat(robloxReconciler)

local Roact = strict({
	Component = require(script.Component),
	createElement = require(script.createElement),
	createFragment = require(script.createFragment),
	oneChild = require(script.oneChild),
	PureComponent = require(script.PureComponent),
	None = require(script.None),
	Portal = require(script.Portal),
	createRef = require(script.createRef),
	forwardRef = require(script.forwardRef),
	createBinding = Binding.create,
	joinBindings = Binding.join,
	createContext = require(script.createContext),

	Change = require(script.PropMarkers.Change),
	Children = require(script.PropMarkers.Children),
	Event = require(script.PropMarkers.Event),
	Ref = require(script.PropMarkers.Ref),

	mount = robloxReconciler.mountVirtualTree,
	unmount = robloxReconciler.unmountVirtualTree,
	update = robloxReconciler.updateVirtualTree,

	reify = reconcilerCompat.reify,
	teardown = reconcilerCompat.teardown,
	reconcile = reconcilerCompat.reconcile,

	setGlobalConfig = GlobalConfig.set,

	-- APIs that may change in the future without warning
	UNSTABLE = {},
})

return Roact

This error is usually an omission, You are trying to execute as a function, something that is not a function. Happens to me all the time. Must be a bug in one of the required modules, as the modules are executed upon requiring and they may contain some auto code.

Example (incorrect):

RemoteEvents = {
   Damage = game.ReplicatedStorage.Events.Damage,
}
RemoteEvents.Damage(game.Players.Sleazel, 'damage', 100)

Correct:

RemoteEvents.Damage:FireClient(game.Players.Sleazel, 'damage', 100)

In short, I’ll have to create a reference to every single module script?

I want it to be able to be used in other scripts, like LocalScripts.

There’s no way the error is coming from that first code snippet. What code is erroring?

This is the localscript of which I’m trying it out on. And the same one which is giving the errors

local Pollen = require(game.ReplicatedStorage.PollenInit)

local players = game:GetService("Players").LocalPlayer.PlayerGui

local screengui = Pollen.createElement("ScreenGui")
Pollen.render(screengui, players, "TestScreen")

local myButton = Pollen.createElement("TextLabel", { 
	Text = "Some Text Here" ;
	BackgroundColor3 = Color3.fromRGB(255, 255, 255);
	TextColor3 = Color3.fromRGB(255, 0, 4);
	BorderColor3 = Color3.fromRGB(0, 0, 0);
	Size = UDim2.new(0.19, 0,0.101, 0);
})

Pollen.render(myButton, screengui, "Text")
Pollen.alignElement(myButton, "AlignTopCenter")

It works if I reference each module, but not when I use it via the Initializer

No. That is not what I meant. I meant the bug is inside either:

  • alignElement,
  • createElement,
  • createTween
  • or render
    modules. One common mistake with module functions is that they return the result of a function and not the function itself.
---module script
function alignElement()
   print("I am aligning this, sit tight")
   return true
end

--correct
return alignElement 
--incorrect
return alignElement() -- this won't work, but will not error. However `Pollen.alignElement` is not a function, it is now a boolean and will give you aforementioned error.

I have checked all the module scripts, and none of them had that, so it can’t be the issue

Like I said, you are definitely trying to call (execute as a function) something that is not a function. This error is definitely in one of Your modules.

Rest is just my speculation, as You have not provided the source of the modules. I did my best to provide you with example mistakes, that is all I can do without seeing scripts.

alright, I’ll send an RBXM file

PollenUi.rbxm (2.6 KB)

this is the rbxm file for whoever needs it

Are you sure this isnt the Culprit?

that’s the RoAct comparison, my script is the first one

1 Like

So you want your modules to return only the function. Returning a dictionary is unnecessary and won’t work without specifying which function you want to call. I suggest to modify Your modules, but you may also modify Your local script to specify that.

--module script
-- local Pollen = {} -- remove this line
function render(element, parent, name) --modify this line this way
	element.Parent = parent
	if name then
		element.Name = name
	end
end

return render -- return the function and not the table.

And so on for other scirpts.

EDIT:
If you want Your modules to stay as they are, you will need to use them in the `LocalScript’ like this:

Pollen.render.render(myButton, screengui, "Text")

I gather that this was not the intention.

alright, thanks…

And yes, it wasn’t intended to be used that way

You’re welcome.

As for the createTween module this solution will not work, since there are more than one function that needs to be returned.

In this case, leave the module as it is. (although I would suggest to change the ‘Pollen’ word inside the module to ‘module’, as it is misleading) Then, you have to specify in local script, which tween you want to use:

--example
Pollen.createTween.tweenSize(....)

Have a nice day.

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