Help with Tables

I’m working on a system where a table stores a bunch of BindableFunctions
Although when I invoke the Function it errors “attempt to call a table value”

Buttons.ColorsOX.MouseButton1Down:Connect(function()
	warn("Activated")
	for i=1,#ConnectedConnections do
		local Object = ConnectedConnections[i]
		warn(Object.ClassName)
		Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
	end
end)

I know obviously the script is calling the value inside the table instead of the instance itself, I just dont know how I can get the instance.

bindable events cant pass tables as an argument. you might wanna serialize it

Try this

Buttons.ColorsOX.MouseButton1Down:Connect(function()
	warn("Activated")
	for i, Object in pairs(ConnectedConnections) do
		warn(Object.ClassName)
		Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
	end
end)

I’ve updated the code a little, still didn’t work

Buttons.ColorsOX.MouseButton1Down:Connect(function()
	warn("Activated")
	for i, Object in pairs(Connections) do
		local Object = Connections[i]
		warn(Object.ClassName)
		local Bind = Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
	end
end)

I’m not passing a table though I’m firing a BindableFunction that’s stored in a table

dont do “i” thing just

Buttons.ColorsOX.MouseButton1Down:Connect(function()
	warn("Activated")
	for i, Object in pairs(Connections) do
		warn(Object.ClassName)
		local Bind = Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
	end
end)

directly.

Wait why are you doing local Object = Connections[i] when you’re already looping through the connections table via that for loop?

for i, Object in pairs(Connections) do
    if Object:IsA("BindableFunction") then
        local Bind = Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
    else
        warn(Object.ClassName, "is not a BindableFunction x_x")
    end
end)

Yeah I just saw that a few minutes ago,
heres my updated code

Buttons.ColorsOX.MouseButton1Down:Connect(function()
	warn("Activated")
	for i, Object in pairs(Connections) do
		warn(Object.ClassName)
		local Bind = Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))
	end
end)

Can you show us the Connections table? Like where it’s being set.

I don’t need to check if its a bindable because this table already does that

for i=1,#Connections do
	local Object = Connections[i]
	local Bind = Object:Invoke("ColoredFog", Channel, nil, nil)	
	if Bind == true then
		Channel = Channel + 1
	else
		table.remove(Connections, Object)
	end
end

It should work, when an BindableFunction returns an error, the error can be from the receiver or the sender, what is the code that receives the information?

Connect.OnInvoke = function(ID, Channel, Change, Value)
-- The rest of the code just uses the data to perform tasks
end

I mean the code that puts the BindableFunctions into the Connections table. Like if you did something like this:

local Connections = {}

for i = 1, math.random(10) do
    local Bindable = Instance.new("BindableFunction")
    Bindable.Name = "SomeEventName"
    table.insert(Connections, Bindable)
end

The code you showed here is just looking inside of that table of BindableFunctions.

The Error is on this line

local Bind = Object:Invoke("ColoredFog", nil, "Color", Color3.new(0,1,0))

In the sending script

For more information on what the script is actually doing, I’m creating a stage lighting system that allows for a main control panel to control other fixures/effects. The script looks through workspace to find bindable events named “Connect” if it finds any, it will talk to them to confirm they are the right fixture. If its not the right type of fixure its looking for it will remove it from this table of bindables. Does that make sense? haha

image
“Handler” is the script that receives the information

So, tested in studio with another BindableFunction, it does not give the error, so it must be an error from which it receives the information, or perhaps it thinks it is a table? or there is a table infiltrate.

Also in the script that receives the information there may be something like Color3() or CFrame() which is what could generate the error.

Alright, after adding some prints it leads to this code (Inside the receiving script)

if Change == "Color" then
				warn("Color has been called")
				local tween = TweenService:Create(script.Parent.LED, TweenInfo(0.5), {Color = Value})
				tween:Play()
				--script.Parent.LED.Color = Value

This error started when I starting messing around with tweens, any chance it has to do with that?

Yep, error found

It should be like this since TweenInfo is like a table and the new method is used to create it

local tween = TweenService:Create(script.Parent.LED, TweenInfo.new(0.5), {Color = Value})
1 Like

Thank you so much, it works no errors!

1 Like