Hello,
First sorry for my bad english.
I have a problem with my DataStore.
Script print Data saved successfully but it isn’t.
I have script located in ServerScriptService.
Here is my script:
--SETTINGS--
local DataStoreName = "KnifeBattleDataStore"
--VARIABLES--
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore(DataStoreName)
--FUNCTIONS--
--PLAYER ADDED--
game.Players.PlayerAdded:Connect(function(Player)
-----------NUMBERS FOLDER------------
local Numbers = Instance.new("Folder")
Numbers.Name = "Numbers"
Numbers.Parent = Player
-----------MONEY VALUE---------------
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = Numbers
-----------GEMS VALUE---------------
local Gems = Instance.new("IntValue")
Gems.Name = "Gems"
Gems.Parent = Numbers
-----------LEVEL VALUE---------------
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = Numbers
-----------EXPERIENCE VALUE---------------
local Experience = Instance.new("IntValue")
Experience.Name = "Experience"
Experience.Parent = Numbers
--DATA LOAD--
local MoneyData
local GemsData
local LevelData
local ExperienceData
local success, errormessage = pcall(function()
MoneyData = MyDataStore:GetAsync(Player.UserId.."-Money")
GemsData = MyDataStore:GetAsync(Player.UserId.."-Gems")
LevelData = MyDataStore:GetAsync(Player.UserId.."-Level")
ExperienceData = MyDataStore:GetAsync(Player.UserId.."-Experience")
end)
if success then
Money.Value = MoneyData
Gems.Value = GemsData
Level.Value = LevelData
Experience.Value = ExperienceData
else
print("There was an error whilist getting your data.")
warn(errormessage)
end
end)
--PLAYER REMOVING--
game.Players.PlayerRemoving:Connect(function(Player)
--DATA SAVE--
local success, errormessage = pcall(function()
MyDataStore:SetAsync(Player.UserId.."-Money",Player.Numbers.Money.Value)
MyDataStore:SetAsync(Player.UserId.."-Gems",Player.Numbers.Gems.Value)
MyDataStore:SetAsync(Player.UserId.."-Level",Player.Numbers.Level.Value)
MyDataStore:SetAsync(Player.UserId.."-Experience",Player.Numbers.Experience.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error when saving data.")
warn(errormessage)
end
end)