i don’t care how to load and save DataStore2, every time getting this error :
Not running script because past shutdown deadline (x34)
DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.
Here is my code :
local MarketPlaceService = game:GetService('MarketplaceService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TextChatService = game:GetService("TextChatService")
local BadgeService = game:GetService('BadgeService')
local RunService = game:GetService('RunService')
local Players = game:GetService('Players')
------------------------------------------------------------------
local AssetFolder = ReplicatedStorage.AssetFolder
local Modules = ReplicatedStorage.Modules
local SystemsModules = Modules.Systems
local Events = ReplicatedStorage.Events
local towerInfo = require(Modules.TowerInfo)
local getData = Events.getData
------------------------------------------------------------------
local DataStoreKey = 'U:TD_Main'
local DataStore2 = require(SystemsModules.DataStore2)
DataStore2.Combine(DataStoreKey, 'U:TD')
local Data = {}
local DataExample = {
['Coins'] = 250,
['Donate'] = 0,
['Gems'] = 0,
['GamesPlayed'] = 0,
['Loses'] = 0,
['Wins'] = 0,
['loggedBefore'] = os.time,
['OwnedTowers'] = {'Shooter'},
['SelectedTowers'] = {'Shooter'},
['OwnedSkins'] = {},
['SelectedSkins'] = {},
['OwnedPowerups'] = {},
['SelectedPowerups'] = {},
['OwnedEmotes'] = {},
['EquippedEmotes'] = {},
['CodesRedeemed'] = {},
['Level'] = 1,
['Battlepass'] = {},
['BattlepassExp'] = 125,
['BattlepassLevel'] = 100,
["BattlepassExpNeed"] = 150,
['MaxSelectedTowers'] = 5,
['MaxSelectedPowers'] = 5
}
local Badges = {
['Voider'] = 12345678, -- // Put Bage id here.
}
------------------------------------------------------------------
local function loadData(Player : Player)
local Success = nil
local playerData = nil
local attempt = 1
local Storage = DataStore2(DataStoreKey, Player)
repeat
Success, playerData = pcall(function()
return Storage:Get({})
end)
attempt += 1
if not Success then
task.wait(0.25)
end
until Success or attempt >= 3
if Success then
if playerData ~= nil then
Data[Player.UserId] = playerData
else
Data[Player.UserId] = DataExample
print('g')
end
for i, v in pairs(Badges) do
if BadgeService:UserHasBadgeAsync(Player.UserId, v) then
if not table.find(playerData.OwnedTowers, i) then
table.insert(playerData.OwnedTowers, i)
end
end
end
else
return Player:Kick('DataStore2 error, please rejoin later.')
end
end
local function SaveData(Player : Player)
if Data[Player.UserId] then
local Storage = DataStore2(DataStoreKey, Player)
Storage:Set(Data[Player.UserId])
end
end
local kickActivity = true
Players.PlayerAdded:Connect(function(Player)
task.spawn(function()
loadData(Player)
_G['Data'] = Data
for i, v in pairs(Admins) do
if kickActivity then
if not table.find(Admins, v) then
Player:Kick('\nGame is closed right now, we are sorry. \n\n Come back later!')
end
end
end
end)
end)
Players.PlayerRemoving:Connect(function(Player)
SaveData(Player)
end)
------------------------------------------------------------------
getData.OnServerInvoke = function(Player : Player)
local UserId = Player.UserId
if Data[UserId] ~= nil then
return Data[UserId]
else
return DataExample
end
end
------------------------------------------------------------------