Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataStore is messy/too many keys? Any advice?

Asked by 5 years ago

So I'm making this stat system with five different. Stat Int Values. Strength, Agility, Stamina, Armour, and Regen. Everything works fine except when I show people my script for help they often say its too messy of a datastore. I don't know how to improve of it so if anyone could give me a heads up that would be nice.

--Strength DataStore
local DataStoreService = game:GetService("DataStoreService")
 StrengthD = DataStoreService:GetDataStore("PlayerStrength4")
--Armour DataStore
local DataStoreService = game:GetService("DataStoreService")
ArmourD = DataStoreService:GetDataStore("PlaryerArmour3")
--Regen DataStore
local DataStoreService = game:GetService("DataStoreService")
RegenD = DataStoreService:GetDataStore("PlaryerRegen3")
--RegenF
local DataStoreService = game:GetService("DataStoreService")
RegenFD = DataStoreService:GetDataStore("PlaryerRegenF3")
--Agility DataStore
local DataStoreService = game:GetService("DataStoreService")
AgilityD = DataStoreService:GetDataStore("PlaryerAgility3")
--Stamina DataStore
local DataStoreService = game:GetService("DataStoreService")
StaminaD = DataStoreService:GetDataStore("PlaryerStamina3")
--StamMin DataStore
local DataStoreService = game:GetService("DataStoreService")
StamMinD = DataStoreService:GetDataStore("PlaryerStamMin4")
--StamMax DataStore
local DataStoreService = game:GetService("DataStoreService")
StamMaxD = DataStoreService:GetDataStore("PlaryerStamMax4")
--Rank DataStore
local DataStoreService = game:GetService("DataStoreService")
RankD = DataStoreService:GetDataStore("PlayerRanks4")
--DiceDR DataStore
local DataStoreService = game:GetService("DataStoreService")
DiceDRD = DataStoreService:GetDataStore("PlaryerDice3")




game.Players.PlayerAdded:Connect(function(Player)
    local char = Player.Character or Player.CharacterAdded:Wait()
    local Stats = Instance.new("Folder")
    Stats.Parent = Player
    Stats.Name = "Stats"
    --Strength--
    local Strength = Instance.new("IntValue",Stats)
    Strength.Name = "Strength"
    local StrengthF = Instance.new("IntValue",char)
    StrengthF.Name = "StrengthF"
    --Armour--
    local Armour = Instance.new("IntValue",Stats)
    Armour.Name = "Armour"
    --Regen--
    local Regen = Instance.new("IntValue",Stats)
    Regen.Name = "Regen"
     RegenF = Instance.new("IntValue",Regen)
    RegenF.Name = "RegenF"
    RegenF.Value = Regen.Value/20
    --Agility--
    local Agility = Instance.new("IntValue",Stats)
    Agility.Name = "Agility"
    local AgilityF = Instance.new("IntValue",char)
    AgilityF.Name = "AgilityF"
    --Stamina--
    local Stamina = Instance.new("IntValue",Stats)
    Stamina.Name = "Stamina"
    local StamMin = Instance.new("IntValue",Stamina)
    StamMin.Name = "StamMin"
    StamMin.Value = Stamina.Value * 15 + 100
    local StamMax = Instance.new("IntValue",Stamina)
    StamMax.Name = "StamMax"
    StamMax.Value = Stamina.Value * 15 + 100
    --Rank--
    local Rank = Instance.new("IntValue",Stats)
    Rank.Name = "Rank"
    --DiceDR--
    local DiceDR = Instance.new("IntValue",Stats)
    DiceDR.Name = "DiceD-Rank"
    --GetAsync's--
    Strength.Value = StrengthD:GetAsync(Player.UserId) or 1
    Armour.Value = ArmourD:GetAsync(Player.UserId) or 0
    Regen.Value = RegenD:GetAsync(Player.UserId) or 1 
    Agility.Value = AgilityD:GetAsync(Player.UserId) or 1
    Stamina.Value = StaminaD:GetAsync(Player.UserId) or 1
    Rank.Value = RankD:GetAsync(Player.UserId) or 1
    DiceDR.Value = DiceDRD:GetAsync(Player.UserId) or 0
    StamMin.Value = StamMinD:GetAsync(Player.UserId) or 100
    StamMax.Value = StamMaxD:GetAsync(Player.UserId) or 100
    RegenF.Value = RegenFD:GetAsync(Player.UserId)
    --Give Maxes--
   Strength.Changed:Connect(function() StrengthChange(Player,Strength) end) 
    function StrengthChange(Player,Strength)
     if Strength.Value > 200 then
        Strength.Value = 200
    end
    end
    Regen.Changed:Connect(function() RegenChange(Player,Regen,RegenF) end) 
    function RegenChange(Player,Regen,RegenF)
     if Regen.Value > 70 then
        Regen.Value = 70
    end
    end
    Agility.Changed:Connect(function() AgilityChange(Player,Agility) end) 
    function AgilityChange(Player,Agility)
     if Agility.Value > 70 then
        Agility.Value = 70
    end
    end
    DiceDR.Changed:Connect(function() DiceDRChange(Player,DiceDR) end) 
    function DiceDRChange(Player,DiceDR)
     if DiceDR.Value <= 0 then
        DiceDR.Value = 0
    end
    end
        Stamina.Changed:Connect(function() StaminaChange(Player,Stamina,StamMax) end) 
    function StaminaChange(Player,Stamina,StamMax)
        StamMax.Value = Stamina.Value * 15 + 100
     if Stamina.Value > 250 then
        Stamina.Value = 250
    end
    end
    StamMin.Changed:Connect(function() StamMinChange(Player,StamMin,StamMax) end) 
    function StamMinChange(Player,StamMin,StamMax)
    if StamMin.Value <= 0 then
        StamMin.Value = 0
    end
    end
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Names.Text = Player.Name
if Rank.Value == 1  then
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Rank.Text = "Rank D"
end
if Rank.Value == 2  then
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Rank.Text = "Rank C"
end 
if Rank.Value == 3  then
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Rank.Text = "Rank B"
end
if Rank.Value == 4  then
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Rank.Text = "Rank A"
end    
if Rank.Value == 5  then
    Player.PlayerGui.GuiStastictics.HealthBarLocater.Rank.Text = "Rank S"
end
if Rank.Value == 1  then
    Player.Character.Head.PlayerBill.Frame.PlayerRank.Text = "Rank D"
end
if Rank.Value == 2  then
    Player.Character.Head.PlayerBill.Frame.PlayerRank.Text = "Rank C"
end 
if Rank.Value == 3  then
    Player.Character.Head.PlayerBill.Frame.PlayerRank.Text = "Rank B"
end
if Rank.Value == 4  then
    Player.Character.Head.PlayerBill.Frame.PlayerRank.Text = "Rank A"
end    
if Rank.Value == 5  then
    Player.Character.Head.PlayerBill.Frame.PlayerRank.Text = "Rank S"
end
Player.Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end)




game.Players.PlayerRemoving:Connect(function(Player)
    StrengthD:SetAsync(Player.UserId, Player.Stats.Strength.Value)
    ArmourD:SetAsync(Player.UserId, Player.Stats.Armour.Value)
    RegenD:SetAsync(Player.UserId, Player.Stats.Regen.Value)
    AgilityD:SetAsync(Player.UserId, Player.Stats.Agility.Value)
    StaminaD:SetAsync(Player.UserId, Player.Stats.Stamina.Value)
    RankD:SetAsync(Player.UserId, Player.Stats.Rank.Value)
    DiceDRD:SetAsync(Player.UserId, Player.Stats["DiceD-Rank"].Value)
    StamMinD:SetAsync(Player.UserId, Player.Stats.Stamina.StamMin.Value)
    StamMaxD:SetAsync(Player.UserId, Player.Stats.Stamina.StamMax.Value)
    RegenFD:SetAsync(Player.UserId, Player.Stats.Regen.RegenF.Value)
end)





0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
View all comments (11 more)
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
my eyes hurt' BashGuy10 384 — 5y
0
come on BashGuy10 384 — 5y
0
come on BashGuy10 384 — 5y
0
come on BashGuy10 384 — 5y
0
come on BashGuy10 384 — 5y
0
Longest script i have ever seen... Destroyer1234x 52 — 5y

2 answers

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Put all the items you want to save to the datastore in one table then save that table to the datastore.

The player stats table could look like this:

playerStats = {
    Strength = 1,
    Agility = 1,
    Stamina = 1,
    Armour = 1,
    Regen = 1 
}
0
did this work? please mark it as accepted if it works. royaltoe 5144 — 5y
Ad
Log in to vote
-2
Answered by
Tokyo7979 131
5 years ago

Try using a table.

0
You should explain your answer more dude! BashGuy10 384 — 5y

Answer this question