I’m making a save system. I already know my webhook works.
code:
local Datastore = game:GetService("DataStoreService")
local https = game:GetService("HttpService")
local url = (webhook url which i wont show)
local data = Datastore:GetDataStore("data")
player = game.Players.LocalPlayer
local leadstats = Instance.new("Folder")
leadstats.Name = "leaderstats"
leadstats.Parent = player
playerUserId = "Player_"..player.UserId
local checkpoints1 = Instance.new("IntValue")
checkpoints1.Name = "Checkpointch1"
checkpoints1.Parent = leadstats
local temp = Instance.new("IntValue")
temp.Name = "temp"
temp.Parent = leadstats
local chapters = Instance.new("IntValue")
chapters.Name = "chapters"
chapters.Parent = player
game.Players.PlayerAdded:Connect(function(player)
local save
local success, errormsg = pcall(function()
save = data:GetAsync(playerUserId)
end)
if success then
checkpoints1.Value = save
chapters.Value = save
else
game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("DebugScreen"):WaitForChild("DebugFrame").Visible = true
warn(errormsg)
local webhookdata = {["embeds"] = {{
["title"] = "Error",
["description"] = "Something went wrong while loading data.", player.Name, chapters.Value, checkpoints1.Value}}}
local webhookmsg = https:JSONEncode(webhookdata)
https:PostAsync(url, webhookmsg)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormsg
success, errormsg = pcall(function()
local save
save = data:SetAsync(playerUserId)
if success then
checkpoints1.Value = save
print("Data saved")
else
game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("DebugScreen"):WaitForChild("DebugFrame").Visible = true
warn(errormsg)
local webhookdata = {["embeds"] = {{
["title"] = "Error",
["description"] = player.Name, "Something went wrong while saving data.", chapters.Value, checkpoints1.Value}}}
local webhookmsg = https:JSONEncode(webhookdata)
https:PostAsync(url, webhookmsg)
end
end)
end)
i got this idea because studio crashed and the windows crash thingy has the “Please wait until Windows reports the problem to Microsoft”