I’ve made a datastore script for my survival game yesterday with 4 different tables
local SavedMinerals = {}
local SavedResources = {}
local SavedFood = {}
local SavedStats = {}
and I cant figure out how to fix it.
Heres the whole script
local DatastoreService = game:GetService("DataStoreService")
local DataKey1 = 1
local Datastore1 = DatastoreService:GetDataStore(DataKey1)
local DataKey2 = 2
local Datastore2 = DatastoreService:GetDataStore(DataKey2)
local DataKey3 = 3
local Datastore3 = DatastoreService:GetDataStore(DataKey3)
local DataKey4 = 4
local Datastore4 = DatastoreService:GetDataStore(DataKey4)
local SavedMinerals = {}
local SavedResources = {}
local SavedFood = {}
local SavedStats = {}
game.Players.PlayerAdded:Connect(function(plr)
wait(2)
--//Stats
SavedStats.Stats = Instance.new("Folder",plr) SavedStats.Stats.Name = 'Stats';
SavedStats.Strength = Instance.new("IntValue",SavedStats.Stats) SavedStats.Strength.Name = 'Strength';
SavedStats.Speed = Instance.new("IntValue",SavedStats.Stats) SavedStats.Speed.Name = 'Speed';
SavedStats.Charm = Instance.new("IntValue",SavedStats.Stats) SavedStats.Charm.Name = 'Charm';
SavedStats.Karma = Instance.new("IntValue",SavedStats.Stats) SavedStats.Karma.Name = 'Karma';
SavedStats.Trust = Instance.new("IntValue",SavedStats.Stats) SavedStats.Trust.Name = 'Trust';
SavedStats.Building = Instance.new("IntValue",SavedStats.Stats) SavedStats.Building.Name = 'Building Level';
SavedStats.Crafting = Instance.new("IntValue",SavedStats.Stats) SavedStats.Crafting.Name = 'Crafting Level';
SavedStats.Forging = Instance.new("IntValue",SavedStats.Stats) SavedStats.Forging.Name = 'Forging Level';
SavedStats.Violence = Instance.new("IntValue",SavedStats.Stats) SavedStats.Violence.Name = 'Violence Level';
SavedStats.Immune = Instance.new("IntValue",SavedStats.Stats) SavedStats.Immune.Name = 'Immune System';
SavedStats.Socialization = Instance.new("IntValue",SavedStats.Stats) SavedStats.Socialization.Name = 'Socialization Level';
SavedStats.Level = Instance.new("IntValue",SavedStats.Stats) SavedStats.Level.Name = 'Level';
--//Minerals
SavedMinerals.Minerals = Instance.new("Folder",plr) SavedMinerals.Minerals.Name = 'Materials';
SavedMinerals.Coal = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Coal.Name = 'Coal';
SavedMinerals.Stone = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Stone.Name = 'Stone';
SavedMinerals.Amethyst = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Amethyst.Name = 'Amethyst';
SavedMinerals.Gold = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Gold.Name = 'Gold';
SavedMinerals.Diamond = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Diamond.Name = 'Diamond';
SavedMinerals.Emerald = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Emerald.Name = 'Emerald';
SavedMinerals.Sulfur = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Sulfur.Name = 'Sulfur';
SavedMinerals.Copper = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Copper.Name = 'Copper';
SavedMinerals.Steel = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Steel.Name = 'Steel';
SavedMinerals.Iron = Instance.new("IntValue",SavedMinerals.Minerals) SavedMinerals.Iron.Name = 'Iron';
--//Resources
SavedResources.Resources = Instance.new("Folder",plr) SavedResources.Resources.Name = 'Resources';
SavedResources.Wood = Instance.new("IntValue",SavedResources.Resources) SavedResources.Wood.Name = 'Wood';
SavedResources.Sticks = Instance.new("IntValue",SavedResources.Resources) SavedResources.Sticks.Name = 'Sticks';
SavedResources.Sugar = Instance.new("IntValue",SavedResources.Resources) SavedResources.Sugar.Name = 'Sugar';
SavedResources.Ice = Instance.new("IntValue",SavedResources.Resources) SavedResources.Ice.Name = 'Ice';
SavedResources.Plastic = Instance.new("IntValue",SavedResources.Resources) SavedResources.Plastic.Name = 'Plastic';
SavedResources.Glass = Instance.new("IntValue",SavedResources.Resources) SavedResources.Glass.Name = 'Glass';
SavedResources.Fur = Instance.new("IntValue",SavedResources.Resources) SavedResources.Fur.Name = 'Fur';
SavedResources.Cloth = Instance.new("IntValue",SavedResources.Resources) SavedResources.Cloth.Name = 'Cloth';
SavedResources.Hide = Instance.new("IntValue",SavedResources.Resources) SavedResources.Hide.Name = 'Hide';
SavedResources.Paper = Instance.new("IntValue",SavedResources.Resources) SavedResources.Paper.Name = 'Paper';
SavedResources.Wool = Instance.new("IntValue",SavedResources.Resources) SavedResources.Wool.Name = 'Wool';
SavedResources.Metal = Instance.new("IntValue",SavedResources.Resources) SavedResources.Metal.Name = 'Metal';
SavedResources.IceShard = Instance.new("IntValue",SavedResources.Resources) SavedResources.IceShard.Name = 'Ice Shard';
SavedResources.MetalScrap = Instance.new("IntValue",SavedResources.Resources) SavedResources.MetalScrap.Name = 'Metal Scrap';
--//Food
SavedFood.Food = Instance.new("Folder",plr) SavedFood.Food.Name = 'Food';
SavedFood.Beef = Instance.new("IntValue",SavedFood.Food) SavedFood.Beef.Name = 'Beef';
SavedFood.Chicken = Instance.new("IntValue",SavedFood.Food) SavedFood.Chicken.Name = 'Chicken';
SavedFood.Steak = Instance.new("IntValue",SavedFood.Food) SavedFood.Steak.Name = 'Steak';
SavedFood.Pork = Instance.new("IntValue",SavedFood.Food) SavedFood.Pork.Name = 'Pork';
SavedFood.Bacon = Instance.new("IntValue",SavedFood.Food) SavedFood.Bacon.Name = 'Bacon';
SavedFood.Bread = Instance.new("IntValue",SavedFood.Food) SavedFood.Bread.Name = 'Ice cold Bread';
SavedFood.Laughter = Instance.new("IntValue",SavedFood.Food) SavedFood.Laughter.Name = 'Laughter';
SavedFood.Leaves = Instance.new("IntValue",SavedFood.Food) SavedFood.Leaves.Name = 'Leaves';
SavedFood.Apples = Instance.new("IntValue",SavedFood.Food) SavedFood.Apples.Name = 'Apples';
SavedFood.Bananas = Instance.new("IntValue",SavedFood.Food) SavedFood.Bananas.Name = 'Bananas';
SavedFood.Oranges = Instance.new("IntValue",SavedFood.Food) SavedFood.Oranges.Name = 'Oranges';
SavedFood.Rice = Instance.new("IntValue",SavedFood.Food) SavedFood.Rice.Name = 'Rice';
SavedFood.RabbitFoot = Instance.new("IntValue",SavedFood.Food) SavedFood.RabbitFoot.Name = 'Rabbit Foot';
SavedFood.Souls = Instance.new("IntValue",SavedFood.Souls) SavedFood.Souls.Name = 'Souls';
SavedFood.Lettuce = Instance.new("IntValue",SavedFood.Food) SavedFood.Lettuce.Name = 'Lettuce';
SavedFood.Grass = Instance.new("IntValue",SavedFood.Souls) SavedFood.Grass.Name = 'Grass';
--//Loading Data
Datastore1:SetAsync(plr.UserId, SavedMinerals)
Datastore2:SetAsync(plr.UserId, SavedResources)
Datastore3:SetAsync(plr.UserId, SavedFood)
Datastore4:SetAsync(plr.UserId, SavedStats)
end)
game.Players.PlayerRemoving:Connect(function(plr)
--//Saving Data
Datastore1:SetAsync(plr.UserId, SavedMinerals)
Datastore2:SetAsync(plr.UserId, SavedResources)
Datastore3:SetAsync(plr.UserId, SavedFood)
Datastore4:SetAsync(plr.UserId, SavedStats)
end)
I`m extremely new to scripting so I really do not understand datastores much.