Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does the data store error when saving data when player leaves?

Script:

function onPlayerRemove(player)
	
	--//Variables\\--
	local Key = "%^&$#" ..player.UserId
	local SpaceCoins = player.leaderstats.SpaceCoins
	local EvoTokens = player.OtherData.EvoTokens
	local Evolutions = player.OtherData.Evolutions
	local Equipped = player.Equipped
	local Pets = player.Pets
	
	local PetTable = {}
	
	for i,v in pairs(Pets:GetChildren()) do
		table.insert(PetTable, v.Value)
	end
	
	local DataTable = {
		SpaceCoins.Value,
		EvoTokens.Value,
		Evolutions.Value,
		PetTable,
		Equipped.Value
	}
	
	--//Save Player Data\\--
	PlayerData:SetAsync(Key, DataTable)
	
	print("Data Saved For " ..player.Name)
end

game.Players.PlayerRemoving:Connect(onPlayerRemove)

Error: 20:13:15.097 - 502: API Services rejected request with error. HTTP 0 (HTTP 403)

1 answer

Give studio access to datastore services by doing the following:

1: Access the game settings in studio 2: Enable the checkbox "Allow studio to access API services"

This should fix your issue. If it doesent, please comment here and I will continue to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.