So I made this simple data store which saves an IntValue, however, upon testing it, it prints that my data was found. Moreover, as I checked the value, nothing changed (meaning the IntValue's value remained at zero). I'm not entirely sure as to what I'm doing wrong but if anyone could show me the issues, I would greatly appreciate it!
Code:
local DataStore = game:GetService("DataStoreService")
local CHPT_Data = DataStore:GetDataStore("CHPT")
game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new("Folder",player)
Folder.Name = "CHPT_Info"
local Info_Val = Instance.new("IntValue",Folder)
Info_Val.Name = "CHPT"
local DT = nil
local Suc, Fail = pcall(function()
DT = CHPT_Data:GetAsync(player.UserId)
end)
if not Suc then
Info_Val.Value = 1
print("no data found")
else
Info_Val.Value = DT
print("data found!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Folder = player:FindFirstChild("CHPT_Info")
local Info_Val = Folder:WaitForChild("CHPT")
local Suc, Fail = pcall(function()
CHPT_Data:SetAsync(player.UserId, Info_Val.Value)
end)
if Suc then
print("Data saved")
else
print("Data not saved!")
end
end)

1 comment
I'm already aware of all this, however, I've found an alternate solution to my issue, but thanks!