So I was using alvinblox's tutorial on how to make a simulator part 3, and I did the data store but when I join the game on roblox and get the numbers to what I want and then rejoin, it didn't save. Heres the code:
local serverStorage = game:GetService("ServerStorage") local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerSave3") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local intelligence = Instance.new("NumberValue") intelligence.Name = "Intelligence" intelligence.Parent = leaderstats local rebirths = Instance.new("IntValue") rebirths.Name = "Rebirths" rebirths.Parent = leaderstats local dataFolder = Instance.new("Folder") dataFolder.Name = player.Name dataFolder.Parent = serverStorage.RemoteData local debounce = Instance.new("BoolValue") debounce.Name = "Debounce" debounce.Parent = dataFolder local intelligenceData, rebirthsData local success,errormessage = pcall(function() intelligenceData = DataStore:GetAsync("intelligence-"..player.UserId) rebirthsData = DataStore:GetAsync("rebirths-"..player.UserId) end) if success then if intelligenceData then intelligence.Value = intelligenceData rebirths.Value = rebirthsData end end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetSync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value) DataStore:SetSync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value) end) end)
What is wrong here? [I did not add the size as I don't want that.]
You should put any errors you have next time, but I think I see the problem anyways.
game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetSync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value) DataStore:SetSync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value) end) end)
DataStore:SetSync()
does not exist as a real function. What you're looking for is DataStore:SetAsync()
game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() DataStore:SetAsync("intelligence-"..player.UserId,player.leaderstats.Intelligence.Value) DataStore:SetAsync("rebirths-"..player.UserId,player.leaderstats.Rebirths.Value) end) end)
Closed as Not Constructive by User#24403
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?