I'm trying to ensure that no player data in leaderstats is nil by using metatables. But I'm not sure if metatables can be used with Folders and IntValues.
Here's the code I wrote
local leaderstatsMeta = {}
leaderstatsMeta.__index = {
function()
print("Some data in leaderstats is nil!")
coins.Value = 1
multiplier.Value = 1
rebirths.Value = 0
steps.Value = 1
end,
}
-- GetChildren returns this but I'm not sure there's another way of doing this or if it works
--[[
{
[1] = Coins,
[2] = Multiplier,
[3] = Rebirths,
[4] = Steps
}
]]--
setmetatable(leaderstats:GetChildren(), leaderstatsMeta)
Should I change GetChildren to something else? Is this even possible with metatables? (Sorry if my English is bad it's not my native language)

1 comment
Sorry but your code doesn't work