Bees loading system does not works?
Asked by
4 years ago Edited 4 years ago
Hello, so I have this script and its not working. Like, its working, but if set, for example, 1 bee at my hive, and save the game, it just gonna load this not as 1, but as a whole hive, and i don't know how to fix, and also print shows it as it should, so there's only 1 bee. if someone understood me(because my explanation is really bad), please help!
Here's my code:
001 | local DataStoreService = game:GetService( "DataStoreService" ) |
002 | local DataStore = DataStoreService:GetDataStore( "BeeGameData" ) |
003 | local Cells = workspace:WaitForChild( "Cells" ) |
004 | local Hives = workspace:WaitForChild( "Hives" ) |
006 | function loadBees(player, parent, beesTable) |
007 | print ( unpack (beesTable)) |
008 | if beesTable [ 1 ] ~ = nil then |
009 | for i, bee in pairs (beesTable) do |
010 | local beeValue = Instance.new( "IntValue" ) |
011 | print (bee.Name, "-" , bee.Slot) |
012 | beeValue.Name = bee.Name |
013 | beeValue.Value = bee.Slot |
014 | beeValue.Parent = parent |
017 | for beeNum = 0 , player.CoreStats.BeesAmount.Value do |
018 | local beeID = Instance.new( "IntValue" ) |
021 | beeID.Parent = player.CoreStats.BeeIDs |
024 | print ( "Player does not have bees" ) |
027 | local beeValue = Instance.new( "IntValue" ) |
028 | beeValue.Name = "None" |
030 | beeValue.Parent = parent |
032 | local beeID = Instance.new( "IntValue" ) |
035 | beeID.Parent = player.CoreStats.BeeIDs |
040 | game.Players.PlayerAdded:Connect( function (Player) |
041 | local coreStats = Instance.new( "Folder" ) |
042 | coreStats.Name = "CoreStats" |
043 | coreStats.Parent = Player |
045 | local Honey = Instance.new( "IntValue" ) |
047 | Honey.Parent = coreStats |
049 | local Pollen = Instance.new( "IntValue" ) |
050 | Pollen.Name = "Pollen" |
051 | Pollen.Parent = coreStats |
053 | local Claimed = Instance.new( "StringValue" ) |
054 | Claimed.Name = "HiveClaimed" |
055 | Claimed.Parent = Player |
057 | local Bees = Instance.new( "Folder" ) |
059 | Bees.Parent = coreStats |
061 | local BeeIDs = Instance.new( "Folder" ) |
062 | BeeIDs.Name = "BeeIDs" |
063 | BeeIDs.Parent = coreStats |
065 | local BeesAmount = Instance.new( "IntValue" ) |
066 | BeesAmount.Name = "BeesAmount" |
067 | BeesAmount.Parent = coreStats |
068 | BeesAmount.Value = 25 |
070 | local data = DataStore:GetAsync(Player.UserId) |
073 | Player.CoreStats.Honey.Value = data.Honey |
074 | Player.CoreStats.Pollen.Value = data.Pollen |
075 | Player.CoreStats.Capacity.Value = data.Capacity |
076 | Player.CoreStats.BeesAmount.Value = data.BeesAmount |
077 | loadBees(Player, Player.CoreStats.Bees, data.Bees) |
079 | loadBees(Player, Player.CoreStats.Bees, { } ) |
082 | game:BindToClose( function () |
084 | saveData.Honey = Player.CoreStats.Honey.Value |
085 | saveData.Pollen = Player.CoreStats.Pollen.Value |
086 | saveData.Capacity = Player.CoreStats.Capacity.Value |
087 | saveData.BeesAmount = Player.CoreStats.BeesAmount.Value |
089 | if Player.HiveClaimed.Value ~ = "" then |
091 | local playerCells = Cells:FindFirstChild(Player.HiveClaimed.Value) |
092 | print (playerCells.Name) |
094 | for _, cell in pairs (Player.CoreStats.Bees:GetChildren()) do |
095 | local test = { Name = cell.Name, Slot = cell.Value } |
096 | table.insert(saveData.Bees, { Name = cell.Name, Slot = cell.Value } ) |
099 | warn( "Player bees wasn't saved, because player did not claimed the hive." ) |
101 | print ( unpack (saveData.Bees)) |
103 | local succes, errormsg = pcall ( function () |
104 | DataStore:SetAsync(Player.UserId, saveData) |
107 | print (Player.Name.. "'s was successfully saved!" ) |
109 | warn( "An error was occured, while saving data:" ,errormsg) |
Thanks!