Leaderstats giving strange error

I’ve been working on some code that has been getting a strange error. I’ve narrowed to done to my leaderstats function causing the issue. I’ve had the function in my script for 3 days now and has working fine until randomly it hasn’t, I haven’t changed anything with it.

My code:

local leaderstats = function() 
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Parent = leaderstats
end
leaderstats()

The error:

CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store:10: Received error: Caught error in reducer
CoreGui.RobloxGui.Modules.PlayerList.Reducers.PlayerKeys:11: attempt to index nil with ‘Money’ - Client - Store:10
20:24:36.003 Stack Begin - Studio
20:24:36.003 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 10 - Studio - Store:10
20:24:36.004 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 152 - function dispatch - Studio - Store:152
20:24:36.004 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 89 - Studio - Store:89
20:24:36.004 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.thunkMiddleware’, Line 30 - Studio - thunkMiddleware:30
20:24:36.004 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 98 - Studio - Store:98
20:24:36.004 Script ‘CorePackages.Packages._Index.roblox_roact-rodux.roact-rodux.connect’, Line 149 - Studio - connect:149
20:24:36.005 Script ‘CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector’, Line 338 - CoreScript - LeaderstatsConnector:338
20:24:36.005 Script ‘CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector’, Line 261 - CoreScript - LeaderstatsConnector:261
20:24:36.005 Stack End - Studio
20:24:36.006 CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store:10: Received error: Caught error in reducer
CoreGui.RobloxGui.Modules.PlayerList.Reducers.PlayerKeys:11: attempt to index nil with ‘Money’ - Client - Store:10
20:24:36.007 Stack Begin - Studio
20:24:36.007 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 10 - Studio - Store:10
20:24:36.007 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 152 - function dispatch - Studio - Store:152
20:24:36.007 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 89 - Studio - Store:89
20:24:36.007 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.thunkMiddleware’, Line 30 - Studio - thunkMiddleware:30
20:24:36.008 Script ‘CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store’, Line 98 - Studio - Store:98
20:24:36.008 Script ‘CorePackages.Packages._Index.roblox_roact-rodux.roact-rodux.connect’, Line 149 - Studio - connect:149
20:24:36.008 Script ‘CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector’, Line 338 - CoreScript - LeaderstatsConnector:338
20:24:36.009 Script ‘CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector’, Line 214 - CoreScript - LeaderstatsConnector:214
20:24:36.009 Stack End - Studio

I have no idea why I’m getting the error or what the contents of it means. The error also isn’t related to my script in any way, it mentions errors from line numbers that don’t exist in my script. If anyone could please explain to me what this is and how to prevent it, it would be very appreciated.

4 Likes

Hey. I’m not entirely sure but it seems like your leaderstats function takes 0 parameters. Maybe try:

local leaderstats = function() 
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Parent = leaderstats
end
leaderstats(player)
2 Likes

I didn’t notice that but it still functions the same because its in a PlayerAdded function and ‘player’ was already predefined. Though I’ll still remove the argument for efficiency.

Perhaps it’d be a better idea to use NumberValue instead?

local leaderstats = function() 
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats
end
leaderstats(player)

Edit: Sorry I haven’t use dev forum in a while now.

This is a server script and player is defined from the first parameter of the PlayerAdded event.

The error still occurs whether it’s a NumberValue or IntValue

I have the same error this morning, scripts have been in place for weeks with no changes, maybe a bug

Hm, I’m not certain about this but I felt like Core stuff getting an error is kind of a rare occasion?, Maybe a plugin is causing it perhaps?, because this is very new to me in a way, most of the core error I usually see is just package error.

local players = game:GetService(“Players”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)

local function leaderstats(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

local money = Instance.new("IntValue")
money.Name = "Money"
money.Parent = leaderstats

end

players.PlayerAdded:Connect(leaderstats)

Getting exactly the same error
runs script to create leaderstats but errors on close
even tried reloading studio case it was bugged
only started happening this evening

It must be a Roblox bug. I use leaderstats and it started happening to me too, yesterday everything worked fine and i didn’t even change anything.

looks to be a roblox bug. I can create other folders for the player on load without issue
its only if I try to create a leaderstats folder

thought I was going nuts earlier

It’s definitely a bug. Before this, the leaderstats and datastore script worked perfectly with no error. Now somehow, it prints out the same long error.

2 Likes

So this will be fixed automatically right?

1 Like

bit of a noob on devforum. Can anyone else report to Roblox plz

1 Like

I don’t know right now. I just hope that they’ll look into it

1 Like

im getting the similar problem

Same problem here, hopefully it will be fixed soon. :slight_smile:

Maybe it doesn’t work because you didn’t define the IntValue’s Value? Not sure, never had your problem.

same here

CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store:10: Received error: Caught error in reducer

CoreGui.RobloxGui.Modules.PlayerList.Reducers.PlayerKeys:11: attempt to index nil with 'EC'  

 08:49:57.920  Stack Begin  -  Studio
  08:49:57.920  Script 'CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store', Line 10  -  Studio - Store:10
  08:49:57.921  Script 'CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store', Line 152 - function dispatch  -  Studio - Store:152
  08:49:57.921  Script 'CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store', Line 89  -  Studio - Store:89
  08:49:57.921  Script 'CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.thunkMiddleware', Line 30  -  Studio - thunkMiddleware:30
  08:49:57.921  Script 'CorePackages.Packages._Index.roblox_rodux-7f8538c6-2ea111e5.rodux.Store', Line 98  -  Studio - Store:98
  08:49:57.922  Script 'CorePackages.Packages._Index.roblox_roact-rodux.roact-rodux.connect', Line 149  -  Studio - connect:149
  08:49:57.922  Script 'CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector', Line 338  -  CoreScript - LeaderstatsConnector:338
  08:49:57.922  Script 'CoreGui.RobloxGui.Modules.PlayerList.Components.Connection.LeaderstatsConnector', Line 261  -  CoreScript - LeaderstatsConnector:261
  08:49:57.922  Stack End  -  Studio

1 Like

Getting the same here. The line in question that throws the error in CoreGui is:

local function createKey(player: Player, primaryStat, stats)
	local stat = primaryStat and stats[player.UserId][primaryStat] or nil <-- This one here
	return {
		name = player.DisplayName:upper(),
		stat = stat and tonumber(stat) or stat,
	}
end

I wonder if it’s something to do with the argument stats sharing a name with the Roblox Global stats()? I don’t know enough about this. Definitely a Roblox issue though.