local DataStore = game:GetService("DataStoreService")
local playdata = DataStore:GetDataStore("playdata")
local function onPlayerJoin(player)
local values = Instance.new("Folder")
values.Name = "values"
values.Parent = player
local clicks = Instance.new("IntValue")
clicks.Name = "Clicks"
clicks.Parent = values
local swordlvl = Instance.new("IntValue")
swordlvl.Name = "SwordLevel"
swordlvl.Parent = values
local save = Instance.new("BoolValue")
save.Name = "save"
save.Parent = game.Players
local playerUserId = "Player_"..player.UserId
local data = playdata:GetAsync(playerUserId)
if data then
clicks.Value = data["Clicks"]
swordlvl.Value = data["SwordLevel"]
print(clicks.Value)
print(swordlvl.Value)
else
clicks.Value = 0
swordlvl.Value = 0
print("No Data")
end
end
local function create_table(player)
local player_stats = { }
for _, stat in pairs(player.values:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player)
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_"..player.UserId
playdata:SetAsync(playerUserId, player_stats)
end)
if not success then
warn("Could not Save data")
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
COMMUNITY QUESTION
my datastore wont work and prints there is data when its not saving properly please help?
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Please properly format your code
I get no errors when i sue this code i have API settings on and the print values for data always says 0 even if i had no data PLEASE help im stuck on this