Does anyone know how I can make this part of the script right:
local number = Instance.new("IntValue")
number.Name = "Number"
number.Parent = leaderstats
for index, value in pairs(playerValuesTable) do
local newValue = Instance.new("IntValue")
newValue.Name = value
newValue.Parent = playerValues
end
if data then
newValue.Value = data -- heres the problem
number.Value = data
else
number.Value = 0
newValue.Value = 0 -- heres the problem
end
You create newValue locally inside the for loop, and attempting to access it outside of that loop will result in an error. You should define it before the for loop, and then you can access it:
local newValue
for index, value in pairs(playerValuesTable) do
newValue = Instance.new("IntValue")
newValue.Name = value
newValue.Parent = playerValues
end
if data then
newValue.Value = data -- heres the problem
number.Value = data
else
number.Value = 0
newValue.Value = 0 -- heres the problem
end