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)
First thing, DataStore
Service is only for ServerScripts
and LocalScripts
. Also, there is no use for using Gui Buttons for saving Data. You can simple create a ServerScript
, put it in ServerScriptService
. Code : [The one from your code]
local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") 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)
Lemme know if it helps!