Hello, Roblox Developer Community!
I am currently developing a game. However, I am a novice scripter. I am making an auto-saving shop system. I am trying to implement a system in which a BoolValue instance will be changed to true when an item is purchased. I already have this code completed. I need help saving the data.
Here are some snippets of code I have. It simply isn’t saving the data. Also, please don’t question the buyable items, variable names, etc. It’s an interesting game, lol.
A serverscript in ServerScriptService.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("WrathOfMomData")
game.Players.PlayerAdded:Connect(function(plr)
local Data = DataStore:GetAsync(plr.UserId)
if Data then
plr.OwnedKits.Mom.Mom.Value = Data.Mom
print("Loaded") -- This prints when I test the game, but the data from my previous session is not there.
end
end)
This is a serverscript inside of ServerScriptService. Pay attention to comments, as they indicate what works and what doesn’t work. By the way, the value of KitName is “Mom.”
function GiveKit(plr, KitName, Price)
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("WrathOfMomData")
plr:WaitForChild("OwnedKits")[plr.PlayerGui.MainGui.Shop.ItemDisplay.Variables.Type.Value][KitName].Value = true
plr:WaitForChild("leaderstats").MomBux.Value = plr:WaitForChild("leaderstats").MomBux.Value - Price
-- Everything above this works.
DataStore:SetAsync(plr.UserId, {
[KitName] = plr:WaitForChild("OwnedKits")[plr.PlayerGui.MainGui.Shop.ItemDisplay.Variables.Type.Value][KitName].Value;
})
print("Saved") -- This prints when I test the game, but when I rejoin, the data is not there.
end
game.ReplicatedStorage.BoughtKit.OnServerEvent:Connect(GiveKit) --Firing the RemoteEvent works perfectly.
Also, I am testing through the Roblox app, not Studio. I am checkting output via the F9.