Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Datastore won't work, and I have no idea why at all? [Solved] [closed]

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

Here is the whole code which is in one script:

001local DataStoreService = game:GetService("DataStoreService")
002local Stats = DataStoreService:GetDataStore("Stats")
003 
004game.Players.PlayerAdded:connect(function(player)
005 
006    -- get parts for system
007    local info = Instance.new("StringValue", game.Workspace.Player_Information)
008    info.Name = player.Name
009 
010    -- set up other parts
011    Instance.new("StringValue",info).Name = "Inventory"
012    Instance.new("StringValue", info.Inventory).Name = "Gloves"
013    Instance.new("IntValue", info).Name = "Box_Bux"
014    Instance.new("StringValue", info).Name = "Wearing"
015    Instance.new("StringValue", info.Wearing).Name = "Gloves"
View all 135 lines...

Essentially the code is saving player stats, and clothing etc which is all held in objects in the workspace in a player file. (a folder). I don't think there's anything wrong particularly with what I'm saving, It seems to be how it is saving. When I play the game it's so inconstant with saving, when I play on my own, and then leave, it just doesn't save at all. It saved in 2 player test mode however, so I'm not sure what the issue is. I also added in a script with the bind to close function and a wait of 10, however this appeared to change nothing. I'm not sure how to fix this as there are no errors, and people's data gets seemingly randomly reset.

0
I have read a few other posts, and I'll attempt moving the script from workspace to ServerScriptService, and I'll try using bind to close again. Iegoadz 5 — 7y
0
Do not use workspace / lighting for storage use server storage. 2nd Do not use Remove it is deprecated. 3rd do not kick the player if the data fails to load retry instead with a small delay. User#5423 17 — 7y
0
Line 107 and 114 use #gloves_inv User#5423 17 — 7y
0
ah! that was why it wasn't working at all! mustve been giving an error as the for loop was running too many or too few times. I will take your advice too, thank you very much, you have saved me hours of crying lol. Iegoadz 5 — 7y
0
Yeah listen to Kingdom he helped write my Data Store, lets just say he is the Data Store master. GottaHaveAFunTime 218 — 7y

Locked by cabbler, Vulkarin, and MessorAdmin

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Why waste your time making a giant script? I use a very short script that works really well:

01local DataStore = game:GetService("DataStoreService")
02local ds1 = DataStore:GetDataStore("ExampleDataStore")
03 
04game.Players.PlayerAdded:connect(function(player)
05 local leader = Instance.new("Folder",player)
06 leader.Name = "leaderstatus"
07 local Bricks = Instance.new("IntValue",leader)
08 Bricks.Name = "Bricks"
09 Bricks.Value = ds1:GetAsync(player.UserId) or 0
10 ds1:SetAsync(player.UserId, Bricks.Value)
11 Bricks.Changed:connect(function()
12  print("Saving Data")
13  ds1:SetAsync(player.UserId, Bricks.Value)
14  print(player.UserId.."'s Data of"..Bricks.Value.." "..Bricks.Name.."has been saved!")
15end)
View all 25 lines...
Ad