I recently made a Data Store that saves stats in a folder and I believe it works. However upon trying to use it I get no values Any help will be appreciated
– Script(Place 1)
local RS = game:GetService("ReplicatedStorage")
local SaveData = game:GetService("DataStoreService"):GetDataStore("System1")
local Debounce = {}
game.Players.PlayerAdded:Connect(function(Player)
local StatFolder = Instance.New("Folder",Player)
StatFolder.Name = "StatFolder"
local Constitution = Instance.New("IntValue",StatFolder)
Constitution.Name = "Constiution"
Constitution.Value = 0
local Strength = Instance.New("IntValue",StatFolder)
Strength.Name = "Strength"
Strength.Value = 0
local Dexterity = Instance.New("IntValue",StatFolder)
Dexterity.Name = "Dexterity"
Dexterity.Value = 0
local Agility = Instance.New("IntValue",StatFolder)
Agility.Name = "Agility"
Agility.Value = 0
local Intelligence = Instance.New("IntValue",StatFolder)
Intelligence.Name = "Intelligence"
Intelligence.Value = 0
local Charisma = Instance.New("IntValue",StatFolder)
Charisma.Name = "Charisma"
Charisma.Value = 0
local Wisdom = Instance.New("IntValue",StatFolder)
Wisdom.Name = "Wisdom"
Wisdom.Value = 0
local TruePoint = Instance.New("IntValue",StatFolder)
TruePoint.Name = "TruePoint"
TruePoint.Value = 0
local Success, Value = pcall(function()
return SaveData:GetAsync(Player.UserId)
end)
if Success then
if Value then
Constitution.Value = Value[1]
Strength.Value = Value[2]
Dexterity.Value = Value[3]
Agility.Value = Value[4]
Intelligence.Value = Value[5]
Wisdom.Value = Value[6]
Charisma.Value = Value[7]
TruePoint.Value = Value[8]
end
else
Constitution.Value = 0
Strength.Value = 0
Dexterity.Value = 0
Agility.Value = 0
Intelligence.Value = 0
Wisdom.Value = 0
Charisma.Value = 0
TruePoint.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local StatTable = {
Player:WaitForChild("StatFolder").Strength.Value,
Player:WaitForChild("StatFolder").Dexterity.Value,
Player:WaitForChild("StatFolder").Agility.Value,
Player:WaitForChild("StatFolder").Intelligence.Value,
Player:WaitForChild("StatFolder").Wisdom.Value,
Player:WaitForChild("StatFolder").Charisma.Value,
Player:WaitForChild("StatFolder").TruePoint.Value
}
local Success, Error = pcall(function()
return SaveData:SetAsync(Player.UserId, StatTable)
end)
if Error then
print(Error)
end
end)
game:BindToClose(function()
for i,players in pairs(game.Players:GetPlayers()) do
local StatTable = {
players:WaitForChild("StatFolder").Constitution.Value,
players:WaitForChild("StatFolder").Strength.Value,
players:WaitForChild("StatFolder").Dexterity.Value,
players:WaitForChild("StatFolder").Agility.Value,
players:WaitForChild("StatFolder").Intelligence.Value,
players:WaitForChild("StatFolder").Wisdom.Value,
players:WaitForChild("StatFolder").Charisma.Value,
players:WaitForChild("StatFolder").TruePoint.Value
}
local Success, Error = pcall(function()
return SaveData:SetAsync(players.UserId, StatTable)
end)
if Error then
print(Error)
end
end
end)
local TS = game:GetService("TeleportService")
local ID = 192991921
RS.TeleportToCC.OnServerEvent:Connect(function(Player)
if Debounce[Player] then return end
Debounce[Player] = true
local Character = Player.Character
if SaveData:GetAsync(Player.UserId) == nil or 0 then
TS:Teleport(ID,Player)
end
end)
–Script (Place 2)
local DSS = game:GetService("DataStoreService")
local System = DSS:GetDataStore("System1")
local RS = game.ReplicatedStorage
local player = game.Players.LocalPlayer
RS.AddPoint.OnServerEvent:Connect(function(player,concat)
System:GetAsync(player.UserId)
local Con = player:WaitForChild("PowerFolder").Dexterity
local Str = player:WaitForChild("PowerFolder").Strength
local Dex = player:WaitForChild("PowerFolder").Dexterity
local Agi = player:WaitForChild("PowerFolder").Agility
local Int = player:WaitForChild("PowerFolder").Intelligence
local Wis = player:WaitForChild("PowerFolder").Wisdom
local Cha = player:WaitForChild("PowerFolder").Charisma
if concat == "1" then
Agi.Value += 1
print("works")
end
if concat == "2" then
Cha.Value += 1
print("works")
end
if concat == "3" then
Con.Value +=1
print("works")
end
if concat == "4" then
Dex.Value += 1
print("works")
end
if concat == "5" then
Int.Value += 1
print("works")
end
if concat == "6" then
Str.Value +=1
print("works")
end
if concat == "7" then
Wis.Value += 1
print("works")
end
end)