local CurrencyData
local LvData
local CurrentData
local MaxData
local Success, ErrorMessage = pcall(function()
CurrencyData = DataStore:GetAsync(Player.UserId.."-CurrencyData")
LvData = DataStore:GetAsync(Player.UserId.."-LvData")
CurrentData = DataStore:GetAsync(Player.UserId.."-CurrentData")
MaxData = DataStore:GetAsync(Player.UserId.."-MaxData")
end)
if not Success then
print(ErrorMessage)
end
if CurrencyData ~= nil then
Currency.Value = CurrencyData
else
Currency.Value = 0
end
if LvData ~= nil then
Lv.Value = LvData
else
Lv.Value = 1
end
if CurrentData ~= nil then
CurrentXP.Value = CurrentData
else
CurrentXP.Value = 0
end
if MaxData ~= nil then
MaxXP.Value = MaxData
else
MaxXP.Value = 100
end
I think I know what is going on. You’re put the event before everything is loaded in. So as soon they’re loaded in, the event emitted. So put it after every data is loaded.
20:46:43.941 ServerScriptService.NewDataStore:76: attempt to index nil with ‘Changed’ - Server - NewDataStore:76
20:46:43.941 Stack Begin - Studio
20:46:43.941 Script ‘ServerScriptService.NewDataStore’, Line 76 - Studio - NewDataStore:76
20:46:43.941 Stack End - Studio
local DataStore = game:GetService(“DataStoreService”):GetDataStore(“Store”)
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Currency = Instance.new("IntValue")
Currency.Name = "Money"
Currency.Parent = Leaderstats
local Lv = Instance.new("IntValue")
Lv.Name = "Level"
Lv.Parent = Leaderstats
local CurrentXP = Instance.new("IntValue")
CurrentXP.Name = "Current"
CurrentXP.Parent = Lv
local MaxXP = Instance.new("IntValue")
MaxXP.Name = "Max"
MaxXP.Parent = Lv
local CurrencyData
local LvData
local CurrentData
local MaxData
local Success, ErrorMessage = pcall(function()
CurrencyData = DataStore:GetAsync(Player.UserId.."-CurrencyData")
LvData = DataStore:GetAsync(Player.UserId.."-LvData")
CurrentData = DataStore:GetAsync(Player.UserId.."-CurrentData")
MaxData = DataStore:GetAsync(Player.UserId.."-MaxData")
end)
if not Success then
print(ErrorMessage)
end
if CurrencyData ~= nil then
Currency.Value = CurrencyData
else
Currency.Value = 0
end
if LvData ~= nil then
Lv.Value = LvData
else
Lv.Value = 1
end
if CurrentData ~= nil then
CurrentXP.Value = CurrentData
else
CurrentXP.Value = 0
end
if MaxData ~= nil then
MaxXP.Value = MaxData
else
MaxXP.Value = 100
end