So ive gotten it to save when you click a block so then I tried it with a gui button and it seems to not even run the full script. Much help appreciated.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
script.Parent.MouseButton1Click:Connect(function(click)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-points",player.leaderstats.Points.Value)
end)
if success then
print("Saved!!")
else
print("Something is not right!!!")
warn(errormessage)
end
end)
