Hey guys! I am currently making my first game. I originally started by importing free models, plugins, scripts, etc. But I wasn't learning anything and kept getting "viruses". So I scrapped that project and started fresh, attempting to do everything myself. So far, between using the wiki, and watching youtube videos, I have been able to hash together workable scripts. However.. they are not clean. Many redundancies, and silliness abound.
Today I have come to ask for some input. I am attempting to learn and create a datastore to store players money and lvl. I also am trying to store their abilities (Strength, Constitution, Agility, Intelligence). After watching multiple youtube videos, and reading the wiki, I have not been able to learn how to accomplish this cleanly, and correctly. I do believe what I have works, but I know that I can clean it up a ton, and use some arrays to consolidate redundancy, etc. Also, I am not sure if I am creating more tables than I need to, etc. Im pretty sure I could save all of my abilities to one table, instead of separately, but I don't really know how to accomplish this.
Could someone take a look at my script, and give me some pointers if you have time? Thanks!
local DSService = game:GetService('DataStoreService'):GetDataStore('xxxxxxxxxxxxxx')
-- Variables
local uniquekey = "id-"..plr.userId
local leaderstats = Instance.new('IntValue',plr)
local abilities = Instance.new('IntValue',plr)
local colvalue = Instance.new('IntValue')
local lvlvalue = Instance.new('IntValue')
local strvalue = Instance.new('IntValue')
local convalue = Instance.new('IntValue')
local agivalue = Instance.new('IntValue')
local intvalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
lvlvalue.Parent = leaderstats
colvalue.Parent = leaderstats
strvalue.Parent = abilities
convalue.Parent = abilities
agivalue.Parent = abilities
intvalue.Parent = abilities
lvlvalue.Name = 'Lvl'
colvalue.Name = 'Col'
strvalue.Name = 'Strength'
convalue.Name = 'Constitution'
agivalue.Name = 'Agility'
intvalue.Name = 'Intelligence'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
colvalue.Value = GetSaved[1]
lvlvalue.Value = GetSaved[2]
strvalue.Value = GetSaved[3]
convalue.Value = GetSaved[4]
agivalue.Value = GetSaved[5]
intvalue.Value = GetSaved[6]
else
local colSaving = {colvalue.Value}
local lvlSaving = {lvlvalue.Value}
local strSaving = {strvalue.Value}
local conSaving = {convalue.Value}
local agiSaving = {agivalue.Value}
local intSaving = {intvalue.Value}
DSService:SetAsync(uniquekey,colSaving)
DSService:SetAsync(uniquekey,lvlSaving)
DSService:SetAsync(uniquekey,strSaving)
DSService:SetAsync(uniquekey,conSaving)
DSService:SetAsync(uniquekey,agiSaving)
DSService:SetAsync(uniquekey,intSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local coltable = {plr.leaderstats.Col.Value}
local lvltable = {plr.leaderstats.lvl.Value}
local strtable = {plr.leaderstats.str.Value}
local agitable = {plr.leaderstats.agi.Value}
local inttable = {plr.leaderstats.int.Value}
DSService:SetAsync(uniquekey,coltable)
DSService:SetAsyne(uniquekey,lvltable)
DSService:SetAsync(uniquekey,strtable)
DSService:SetAsyne(uniquekey,contable)
DSService:SetAsync(uniquekey,agitable)
DSService:SetAsyne(uniquekey,inttable)
end)

2 comments
I did it for you this time, but in the future please enclose your code within a code block. https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site
oh thank you