Will this work? (Webhooks for pcalls)

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”

1 Like

What is this for? If it’s for error logging of datastores, this will probably work but I don’t really know.

1 Like

Discord does not allow Roblox to send Webhook packets, you’ll first have to work around that via a proxy server before you can get that to properly log. It will only log in studio since it’s using your local address instead of Roblox’s.

Secondly, it’s heavily discouraged by Discord to log errors, especially if it exceeds their rate limits. I would advise against this considering that you might have action taken against you for it.

Other than that, onto your request, yes, it should work for what you intend it to. Granted, datastore errors may vary and not all of them may solely depend on your code.

Yes. It sends a message to my server and gives me the username of a player and their values. i don’t have a good system for saving so if your data doesn’t load you’re screwed because it’s gonna save if you leave.

That’s what ProfileService and DataStore2 are for.

Thank you, I’ll try to research them and use them. I’m also putting :BindToClose() or whatever it’s called because i need to make some stuff with it. I’ll also add :IsStudio() so i can test it out more in Roblox studio.

I’m not sure why you are trying to reference the LocalPlayer since this is supposedly a ServerScript. If it is a LocalScript, it shouldn’t be working since the client can’t make calls to DataStores, and you also shouldn’t handle data on the client, as that would be a gateway for exploiters to manipulate their data.

I didn’t see any reference to the LocalPlayer.

He references it in Line 5 and then again inside his PlayerAdded event as well as his PlayerRemoving one.

Oh, I see that too. I don’t know why he put those there.

i followed devking’s tutorial. in his tutorial it’s a serverscript.