I have written this script over and over and over again and I dont see whats wrong, I have also gone through the page on developer.roblox.com. What am I missing here?
local DataStoreService = game:GetService("DataStoreService")
local InventoryDataStore = DataStoreService:GetDataStore("InventoryStore")
game.Players.PlayerAdded:Connect(function(Player)
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = Player
local slot1 = Instance.new("StringValue")
slot1.Name = "Slot1"
slot1.Parent = inventory
slot1.Value = "nil"
local InventoryStore
local success, err = pcall(function()
InventoryStore = InventoryDataStore:GetAsync(Player.UserId.."-slot1")
end)
if success then
print("Successfully Loaded Inventory Data")
slot1.Value = InventoryStore
else
print("Inventory Data Not loaded Correctly")
end
if slot1.Value == "nil0" then
slot1.Value = "nil"
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success, err = pcall(function()
InventoryDataStore:SetAsync(Player.UserId.."-slot1",Player.Inventory.Slot1.Value)
end)
if success then
print("Inventory Data Successfully Saved")
else
print("Inventory Data Not Saved Correctly")
end
end)
I get the:
502: API Services rejected request with error. HTTP 403 (Forbidden)
If you accept a suggestion from a beginner who suffered a lot using the Roblox native DataStore, I give you the solution: forget about DataStore and use DataStore2.
If API Services are enabled but it is giving a 502 error with HTTP 403, that would mean that your are in team create and you are not the owner, in studio, you can only use data stores if you are the owner, if you aren’t the owner, roblox servers reject the request saying that you are not allowed to access it. Try testing it on the roblox application instead.
It is weird if API Services are enabled but it is giving you that error, there is probably nothing wrong with the code and something wrong with the game settings, try to test it on the roblox application and see what happens.
I did that and it worked just fine saving my data on the client, no errors. Any other ideas on why its just not working in studio? Im going to restart my laptop right now and see if it has anything to do with that.