I got some problems with DataStore, no data showed up after leaving. So basically, i had this Leaderstats, i had this Part, and whenever i click, it add points to "Jewelry". However, when i left the games and then joined back, that data didn't show up (Test both with Play button in Studio and Play the Published game)
local DataStoreService = game:GetService("DataStoreService")
local DataStoreAction = DataStoreService:GetDataStore("DataStoreAction")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Jewelry = Instance.new("IntValue")
Jewelry.Name = "Jewelry"
Jewelry.Parent = leaderstats
local UserID = "Player: "..player.UserId
print(UserID)
local data
local success, errormessage = pcall(function()
data = DataStoreAction:GetAsync(UserID)
end)
if errormessage then
warn(errormessage)
end
if data then
Jewelry.Value = data
print("data loaded")
else
print("no data found")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local UserID = player.UserId
local Data = player.leaderstats.Jewelry.Value
local success, errormessage = pcall(function()
DataStoreAction:SetAsync(UserID, Data)
end)
if errormessage then
warn(errormessage)
end
end)
game.Workspace.JewelryPart.ClickDetector.MouseClick:Connect(function(player)
player.leaderstats.Jewelry.Value += 1
end)