Module function not adding to leaderstats

this is the error I got
image

here’s the function, it should add the called amount to the player’s leaderstats
image

and here is where it is called. it is set up in the correct order, and the module is correctly installed.
image

image

I’m guessing it’s because when the function is called, the leaderstats folder hasn’t been created yet. how can I fix this?

note: the script that the add function is called in is also a module script. and the add function is called inside another function.

1 Like

Are you requiring the module from a local script or a serverscript?

Edit: LocalPlayer is not defined on the server and returns nil, you must define player correctly.

A common way a Player is defined is through a server script is:

game.Players.PlayerAdded:Connect(function(Player)

The issue is probably that you are trying to find the local player on the server

image

You are defning LocalPlayer meaning you are using a local script, and then you are trying to change a value which is within the Player Service, a client cannot access this service. You would want to have your script on the server side. And use a remote function:Fire to server with the information

server script inside server script service.

image
the function is called in ‘module’ and the function is in ‘PlayerData’

LocalPlayer is not defined on the server and returns nil, you must define player correctly.

A common way a Player is defined is through a server script is:

game.Players.PlayerAdded:Connect(function(Player)

@Jxl_s @VellRBX it is in a server script

Read IEnforce_Lawz post, you can’t get the “LocalPlayer” from a server script.

That would probably be your issue: the local player doesn’t exist when you are trying to find it from there

You could do something like this, if you are testing around

game.Players.PlayerAdded:Connect(function(plr)
    data.add(plr, 100)
end)