'roblox: DataStore does not loading data
I made data store but its not loading saves values. I tried on actual servers, still nothing. also its outputs only log, no errors, no warnings.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SkinStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local Cash= Instance.new("IntValue", Leaderstats)
Cash.Name = "Cash"
Cash.Value = 100
local Kills= Instance.new("IntValue", Leaderstats)
Kills.Name = "Kills"
Kills.Value = 0
local Data = DataStore:GetAsync(Player.UserId)
print(Data)
if Data then
Cash.Value = Data["Cash"]
Kills.Value = Data["Kills"]
print("also works")
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, {
["Cash"] = Player.leaderstats.Cash.Value;
["Kills"] = Player.leaderstats.Kills.Value;
})
end)
Solution 1:[1]
There is a problem in the way you're saving the data. You need to add comma "," not semi-colon ";".
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, {
["Cash"] = Player.leaderstats.Cash.Value,
["Kills"] = Player.leaderstats.Kills.Value
})
end)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vector3 |
