where it says NOTE!!! please note
local Module = require(game.ReplicatedStorage.ToolsM)
Tools = Module.SimpleNames
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore = DataStoreService:GetDataStore("102CandySimulatorGameStoreDevAlpha")
local DataTable = {}
local AutosaveInterval = 60*5 --the 5 means 5 mins
local AutosaveTick = 0
local PlayerList = Instance.new("Folder")
PlayerList.Name = "PlayerList"
PlayerList.Parent = ReplicatedStorage
game.Players.PlayerAdded:Connect(function(Player)
-- Getting the key via userid.
local PlayerKey = Player.UserId
-- Creating a folder for all the data.
local PlayerFolder = Instance.new("Folder")
PlayerFolder.Name = Player.Name
PlayerFolder.Parent = PlayerList
-- Checking if they have data.
local PlayerData = DataStore:GetAsync(PlayerKey)
if not PlayerData then
-- If they don't, we create data.
DataTable.Player = {
Level = 1,
currentEXP = 0,
Cash = 0,
AlphaPlayer = 1, --Disable on full version
CandyCorn = true
}
for i = 1, #Tools do
print (Tools[i])
table.insert(DataTable.Player,Tools[i]) --NOTE! sets values to false
DataTable.Player[Tools[i]] = false
end
print (DataTable.Player["CandyCorn"])
DataStore:SetAsync(PlayerKey, DataTable.Player)
wait(2.5)
Player:Kick("New Data Has Been Made Please Rejoin")
else
-- If they do, we set the data.
DataTable.Player = PlayerData
end
-- Creating variables so other scripts can acess the data.
local RealLevel = Instance.new("NumberValue")
RealLevel.Name = "RealLevel"
RealLevel.Value = DataTable.Player["Level"]
RealLevel.Parent = PlayerFolder
local RealEXP = Instance.new("NumberValue")
RealEXP.Name = "RealEXP"
RealEXP.Value = DataTable.Player["currentEXP"]
RealEXP.Parent = PlayerFolder
local MaxEXP = Instance.new("NumberValue")
MaxEXP.Name = "MaxEXP"
MaxEXP.Value = RealLevel.Value * 10 + 70
MaxEXP.Parent = PlayerFolder
local RealCoins = Instance.new("NumberValue")
RealCoins.Name = "RealCoins"
RealCoins.Value = DataTable.Player["Coins"]
RealCoins.Parent = PlayerFolder
--TESTING!!!
wait(1)
local Config = Instance.new ("Configuration")
Config.Name = "ToolsOwned"
Config.Parent = Player
local a = Instance.new ("Configuration")
a.Name = "Hidden"
a.Parent = Player:WaitForChild("Backpack")
a = Instance.new ("StringValue")
a.Name = "CurrentTool"
a.Parent = Config.Parent
for i = 1, #Tools do
a = Instance.new ("BoolValue")
a.Name = Tools[i]
a.Parent = Config
print (Tools[i])
print (DataTable.Player[Tools[i]]) --NOTE! prints out object name and then nil
a.Value = DataTable.Player[Tools[i]]
end
--TESTING!!!
while wait() do
MaxEXP.Value = RealLevel.Value * 10 + 70
-- Leveling part of the loop.
if RealEXP.Value >= MaxEXP.Value then
RealEXP.Value = 0
RealLevel.Value = RealLevel.Value + 1
MaxEXP.Value = RealLevel.Value * 10 + 70
end
-- Doing the autosave for data.
wait(1)
AutosaveTick = AutosaveTick + 1
if AutosaveTick >= AutosaveInterval then
AutosaveTick = 0
-- Updating the data of the player.
DataTable.Player["Level"] = PlayerFolder:FindFirstChild("RealLevel").Value
DataTable.Player["currentEXP"] = PlayerFolder:FindFirstChild("RealEXP").Value
DataTable.Player["Coins"] = PlayerFolder:FindFirstChild("RealCoins").Value
-- Saving the data of the player.
DataStore:SetAsync(PlayerKey, DataTable.Player)
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
-- Getting the key via userid.
local PlayerKey = Player.UserId
-- Finding the data of the player.
local PlayerFolder = PlayerList:FindFirstChild(Player.Name)
if PlayerFolder then
-- Updating the data of the player.
DataTable.Player["Level"] = PlayerFolder:FindFirstChild("RealLevel").Value
DataTable.Player["currentEXP"] = PlayerFolder:FindFirstChild("RealEXP").Value
DataTable.Player["Coins"] = PlayerFolder:FindFirstChild("RealCoins").Value
-- Saving the data of the player.
DataStore:SetAsync(PlayerKey, DataTable.Player)
-- Removing the folder, as we have saved data.
PlayerFolder:Remove()
end
end)
