-
What do you want to achieve?
I’m making a simple subroutine to load all information from a folder containing BlahValues (any value like StringValue, IntValue, etc.) I have this so far:
for i, v in pairs(stats:GetChildren()) do
if v:IsA("ValueBase") then
local name = v.Name
Stats[name] = v.Value
local function onChange()
Stats[name] = v.Value
end
print(Stats)
print(v)
local connection = v.Changed:Connect(onChange)
table.insert(connections,connection)
elseif v:IsA("Folder") then
Stats[v.Name] = {}
for fi, v2 in pairs(v:GetChildren()) do
if v:IsA("ValueBase") then
local name = v2.Name
Stats[v.Name][name] = v2.Value
local function onChange()
Stats[v.Name][name] = v2.Value
end
print(Stats)
print(v)
local connection = v2.Changed:Connect(onChange)
table.insert(connections,connection)
end
end
end
end
Couple of extra things to note. I’m loading the onChange events into the connections array, so I can disconnect them all later. I also made it so that if the value isn’t a whatever value, it creates a new array and places the items in it. (I.e. a folder instead of an IntValue).
2. What is the issue?
I’m currently getting:
Test is not a valid member of folder.
Note that test is the name of the value.
3. What solutions have you tried so far?
I’ve attempted different methods of defining the value under the table, but none have worked. Why is this, and what is the right way to do it?
Thank you for reading this!
EDIT: Updated with Colbert’s suggestions, still getting the same error.
1 Like
What line is the error from (or what section of the script)
Sorry for the late reply, line 13:
Stats[name] = v.Value
Is stats a folder or a table?
30 characters
It is actually a table. 30char
Might have to do with the fact that you’re calling the function, meaning the script is attempting to connect the return value (nil) to a RBXScriptSignal. Replace all instances of v.Changed:Connect(onChange())
with v.Changed:Connect(onChange)
.
Also, values have a superclass called ValueBase. For all cases of using string.find for Value in the ClassName, replace this by calling :IsA("ValueBase")
on any variables.
Thank you for the reply Colbert! I wish I had known about ValueBase beforehand, it is very useful. Anyways, updated the code with your suggestions, but I’m still getting the same error, any ideas?
1 Like
This error looks to be rooted elsewhere. Could you isolate specifically where you’re getting the problem at and show that code? Are you just trying to index Test normally which should be loaded by this code but it’s not loading? I’m not sure that this code is even the issue.
Alright, everything is in a module script. The top looks like:
local Zeppelin = {}
Zeppelin.__index = Zeppelin
local RunService = game:GetService("RunService")
local isServer = RunService:IsServer()
And then I have my local function for loading. In the Zeppelin.New method:
function Zeppelin.new(model, player)
if isServer then
local o = {} -- create object
o.Flashing = false
o.Model = model
o.FlashingValue = 0
o.Stats = {}
o.Connections = {}
o.Stats = model:WaitForChild("Stats")
o.Lighting = model:WaitForChild("Lighting")
o.Creator = player
o.Force = model.MainBody.Balloon.BodyForce
loadInfo(o, model)
--self._index = self
return setmetatable(o, Zeppelin)
else
--Fire Server - Make Later
return nil
end
end
I’m calling Zeppelin.new() in a script in ServerScriptService, passing it the proper arguments. Could this have something to do with metatables, and if so would it be best to incorporate it into the .new function? The point of the local function loadInfo was to allow other functions within the module script to access it too. Thank you for your help!
The point of the code is to add the respective value based upon the ValueBase’s name, and then add it’s value with that key.