local data = {}
local HttpService = game:GetService("HttpService")
local players = game:GetService("Players")
local Datastore2 = require(1936396537) -- Get datastore2 module
Datastore2.Combine("Inventory", "Gold", "Armour", "Potions", "Weapons","Health","Damage","MagicDamage","Level", "Experience","MaxExperience" )
data.AddedEvent = function(player)
--// Inventory System
local Inventory = Instance.new("Folder", player); Inventory.Name = "Inventory"
local playerGold = Instance.new("IntValue", Inventory); playerGold.Name = "Gold"
local playerArmour = Instance.new("StringValue", Inventory); playerArmour .Name = "Armour"
local playerPotions = Instance.new("StringValue", Inventory); playerPotions .Name = "Potions"
local playerWeapons = Instance.new("StringValue", Inventory); playerWeapons .Name = "Weapons"
--// Player Stats
local playerHealth = Instance.new("IntValue", Inventory); playerHealth.Name = "Health"
local playerDamage = Instance.new("IntValue", Inventory); playerDamage.Name = "Damage"
local playerMagicDmg = Instance.new("IntValue", Inventory); playerMagicDmg.Name = "MagicDamage"
--// Players Level
local LevelSystem = Instance.new("Folder", player); LevelSystem.Name = "LevelSystem"
local PlayerLevel = Instance.new("IntValue", LevelSystem); PlayerLevel.Name = "Level"
local PlayerXp = Instance.new("IntValue", LevelSystem); PlayerXp.Name = "Experience"
local PlayerMaxXp = Instance.new("IntValue", LevelSystem); PlayerMaxXp.Name = "MaxExperience"
--// Datastore
local goldStore = Datastore2("Gold", player); local goldStoreData = goldStore:Get()
local armourStore = Datastore2("Armour", player); local armourStoreData = armourStore:Get({ })
local potionsStore = Datastore2("Potions", player); local potionsStoreData = potionsStore:Get({ })
local weaponsStore= Datastore2("Weapons", player); local weaponsStoreData = weaponsStore:Get({ })
local healthStore = Datastore2("Health", player); local healthStoreData = healthStore:Get()
local damageStore = Datastore2("Damage", player); local damageStoreData = damageStore:Get()
local magicStore = Datastore2("MagicDamage", player); local magicStoreData = magicStore:Get()
local levelStore = Datastore2("Level", player); local levelStoreData = levelStore:Get()
local xpStore = Datastore2("Experience", player); local XpStoreData = xpStore:Get()
local maxxpStore = Datastore2("MaxExperience",player); local MaxXpStoreData = maxxpStore:Get()
--// JSON Encode/Decode
playerArmour.Value = HttpService:JSONEncode(armourStoreData) -- Turning your items into a JSON table. we don't need to do this for gold as gold is a number and wont have multiple items inside
armourStore:OnUpdate(function(decodedData)
playerArmour.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
end)
playerPotions.Value = HttpService:JSONEncode(potionsStoreData)
potionsStore:OnUpdate(function(decodedData)
playerPotions.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
end)
playerWeapons.Value = HttpService:JSONEncode(weaponsStoreData)
weaponsStore:OnUpdate(function(decodedData)
playerWeapons.Value = HttpService:JSONEncode(decodedData) -- Encodes newly updated data
end)
end
return data
This is a dataStore2 Module script and I have it being called from a serverscriptservice, and for some reason when I leave the game my values don’t save? It says Inventory saved but nothing really does save, I also have a boolValue in serverStorage called SaveInStudio, set to true but Nothing saves, I usually change my values on the server and then leave to see if they save but they dont. Any reason or am I just being stupid right now. Below is the serverSriptService script.
local players = game:GetService("Players")
local data = require(game.ServerStorage:WaitForChild("Modules"):WaitForChild("DataStoreHandler"))
players.PlayerAdded:Connect(function(player)
data.AddedEvent(player)
end)