So im trying to make an exp system with datastore 2 but im not really good with tweening, how to get the players data, and the required amount of data using DataStore2. Where do i start?
Here is the datahandler if needed:
local replicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
DataStore2.Combine("Data", "Inventory", "Currency", "Level", "Exp")
local defaultLevel = 1
local defaultexp = 0
local DefaultCurrencyAmount = 0
local DefaultHealthAmount = 150
local expToLevelUp = function(level)
return 100 + level * 15
end
game.Players.PlayerAdded:Connect(function(player)
--All the DataStores in here--
local InventoryStore = DataStore2("Inventory", player)
local CurrencyStore = DataStore2("Currency", player)
local ExpStore = DataStore2("Exp", player)
local LevelStore = DataStore2("Level", player)
local replicatedDataFolder = Instance.new("Folder")
replicatedDataFolder.Parent = replicatedStorage.ReplicatedData
replicatedDataFolder.Name = player.UserId
---------------------------------------------
--STARTING THE INVENTORY FUNCTION--
local inventoryString = Instance.new("StringValue")
inventoryString.Parent = replicatedDataFolder
inventoryString.Name = "Inventory"
--Leaderstats--
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local LevelValue = Instance.new("IntValue", leaderstats)
LevelValue.Name = "Level"
local expValue = Instance.new("IntValue", leaderstats)
expValue.Name = "Exp"
----------------------------------------------
--Functions--
local function updateLevel(amount)
player.leaderstats.Level.Value = amount
replicatedStorage.Events.UpdateClientLevel:FireClient(player, amount)
print("Good")
end
local function updateEXP(exp)
if exp >= expToLevelUp(LevelStore:Get(defaultLevel)) then
ExpStore:Increment(expToLevelUp(LevelStore:Get(defaultLevel)) * -1)
LevelStore:Increment(1)
else
player.leaderstats.Exp.Value = exp
end
end
local inventoryData = InventoryStore:Get({})
inventoryString.Value = HttpService:JSONEncode(inventoryData)
InventoryStore:OnUpdate(function(decodedData)
inventoryString.Value = HttpService:JSONEncode(decodedData)
end)
local function updateClientCurrency(amount)
replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
end
updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))
CurrencyStore:OnUpdate(updateClientCurrency)
--call functions right away one time
updateLevel(LevelStore:Get(defaultLevel))
updateEXP(ExpStore:Get(defaultexp))
LevelStore:OnUpdate(updateLevel)
ExpStore:OnUpdate(updateEXP)
end)
game.Workspace:WaitForChild("Bruh").ClickDetector.MouseClick:Connect(function(player)
local CurrencyStore = DataStore2("Currency", player)
CurrencyStore:Increment(1,DefaultCurrencyAmount)
end)
Are you trying to save the data or just get it?
get it, and put it in a textlabel where it would say the amount the of exp someone has and the amount they need
Yes but to do that don’t you need to firstly save the data
With no data to get how is it saved
Resources:
it’s already saved datastore2 automatically saves it
Player removing isn’t needed for datastore2