so on line 23 I get an error saying: ServerScriptService.Leaderstats:23: attempt to index nil with 'UserId'
local DS = game:GetService("DataStoreService")
local CurrencySave = DS:GetDataStore("FirstStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue", leaderstats)
Money.Name = "Money"
Money.Value = 100
local XP = Instance.new("IntValue", leaderstats)
XP.Name = "Level"
XP.Value = 1
local data =
local success, errormessage = pcall(function(player)
data:GetAsync(player.UserId.."-Money")
end)
if success then
Money.Value = data
else
print("There was an error while getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall (function()
CurrencySave:SetAsync(player.UserId.."-Money", player.leaderstats.Money.Value)
end)
if success then
print("Player data Saved!")
else
print("Player Data didn't Save.")
warn(errormessage)
end
end)

2 comments
did you opened HTTP serivces to RobloxStudio ?
yes