Im adding a datastore and ever since I added it I got this error: leaderstats not a valid member of player
01 | local DS = game:GetService( "DataStoreService" ) |
02 | local DS 1 = DS:GetDataStore( "SaveJoins" ) |
03 |
04 | game.Players.PlayerAdded:Connect( function (Player) |
05 | local leaderstats = Player:WaitForChild( "leaderstats" ) |
06 | local Joins = Instance.new( "IntValue" , leaderstats) |
07 | Joins.Name = "Joins" |
08 | Joins.Value = DS 1 :GetAsync(Player.UserId) |
09 | Joins.Value = Joins.Value + 1 |
10 | end ) |
11 |
12 | game.Players.PlayerAdded:Connect( function (Player) |
13 | DS 1 :GetAsync(Player.UserId, Player.leaderstats.Joins.Value) |
14 | end ) |
You didn't create a leaderstats folder. Also you're using 2 PlayerAdded events. My advice is to consolidate everything into one event. (Note: I'll be putting --comments
for anything critical.)
01 | local DS = get:GetService( "DataStoreService" ) |
02 | local DS 1 = DS:GetDataStore( "SaveJoins" ) |
03 |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | local leaderstats = Instance.new( "Folder" ) --You need to create a folder. |
06 | leaderstats.Name = "leaderstats" |
07 | leaderstats.Parent = player |
08 |
09 | local joins = Instance.new( "IntValue" ) --do not use the 2nd parameter of Instance.new() as it is somewhat slower, and considered deprecated. |
10 | joins.Name = "Joins" |
11 | joins.Parent = leaderstats |
12 | end ) |
Edit: At asker's request, I sent a link to Devking's DataStoreService video. DataStoreService
It Doesn't Look Like You Made A leader stats folder. Unless You Made It in Another Script. If You Have Just Delay It. But If You Haven't Then Make A New Instance.
This Script Might Work IF You Haven't Made A leaderstats Folder
01 | local DS = game:GetService( "DataStoreService" ) |
02 | local DS 1 = DS:GetDataStore( "SaveJoins" ) |
03 |
04 | game.Players.PlayerAdded:Connect( function (Player) |
05 | local leaderstats = Instance.new( "Folder" ) |
06 | leaderstats.Name = "leaderstats" |
07 | leaderstats.Parent = Player |
08 |
09 | local Joins = Instance.new( "IntValue" , leaderstats) |
10 | Joins.Name = "Joins" |
11 | Joins.Value = DS 1 :GetAsync(Player.UserId) |
12 | Joins.Value = Joins.Value + 1 |
13 | end ) |
14 |
15 | game.Players.PlayerAdded:Connect( function (Player) |
16 | DS 1 :GetAsync(Player.UserId, Player.leaderstats.Joins.Value) |
17 | end ) |