Hey, I’m trying to make it so my in-game points save with this datastore script but it is erroring and I don’t know why
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
local strength = Instance.new("IntValue")
strength.Name = "Strength"
strength.Value = 0
strength.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error when saving your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
myDataStore:SetAsync(plr.UserId…“-cash”,plr.leaderstats.Cash.Value)
end)
if success then
print(“Player data successfully saved!”)
else
print(“There was ana error when saving your data”)
warn(errormessage)
end
