hey, so i made a datastore script… it’s works perfectly fine but peoples saying that i wrote it wrong and it can make problems in the future
my code:
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("EXPSaveSystem")
local ds2 = datastore:GetDataStore("GOLDSaveSystem")
local ds3 = datastore:GetDataStore("LOVESaveSystem")
local ds4 = datastore:GetDataStore("RESETSaveSystem")
function onXPChanged(plr, EXP, LOVE)
if EXP.Value >= (10 + 25*LOVE.Value) then
EXP.Value = EXP.Value - (10 + 25*LOVE.Value)
LOVE.Value = LOVE.Value + 1
elseif LOVE.Value == 100 then
if EXP.Value >= LOVE.Value*9999999 then
EXP.Value = EXP.Value - LOVE.Value*9999999
end
end
end
function onLOVEChanged(plr, EXP, LOVE)
if LOVE.Value >= 100 then
LOVE.Value = 100
end
end
game.Players.PlayerAdded:connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "GasterVoid"
local GOLD = Instance.new("IntValue", folder)
GOLD.Name = "GOLD"
local EXP = Instance.new("IntValue", folder)
EXP.Name = "EXP"
local LOVE = Instance.new("IntValue", folder)
LOVE.Name = "LOVE"
LOVE.Value = 1
local RESET = Instance.new("IntValue", folder)
RESET.Name = "RESET"
EXP.Value = ds1:GetAsync(plr.UserId) or 0
ds1:SetAsync(plr.UserId, EXP.Value)
GOLD.Value = ds2:GetAsync(plr.UserId) or 0
ds2:SetAsync(plr.UserId, GOLD.Value)
RESET.Value = ds4:GetAsync(plr.UserId) or 0
ds4:SetAsync(plr.UserId, RESET.Value)
LOVE.Value = ds3:GetAsync(plr.UserId) or 0
ds3:SetAsync(plr.UserId, LOVE.Value)
EXP.Changed:connect(function()
ds1:SetAsync(plr.UserId, EXP.Value)
onXPChanged(plr, EXP, LOVE)
end)
GOLD.Changed:connect(function()
ds2:SetAsync(plr.UserId, GOLD.Value)
end)
LOVE.Changed:connect(function()
ds3:SetAsync(plr.UserId, LOVE.Value)
onLOVEChanged(plr, EXP, LOVE)
end)
RESET.Changed:connect(function()
ds4:SetAsync(plr.UserId, RESET.Value)
end)
end)
so basically , as peoples said, storing different data in separate storage is unefficient…
and i have no idea how to make it better…
i have tried many ways and none of them worked like it’s suppose to work