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

API Services rejected request with error. HTTP 403 (Forbidden)?

hi im trying to save my data but i keep getting that error in the output (btw i own the game and i have API Servives On)

my data store script:

local datastore = game:GetService("DataStoreService") local data1 = datastore:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(plr)

local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = plr

local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 5000 
Cash.Parent = folder

-- Save cash Cash.Value = data1:GetAsync(plr.UserId) data1:SetAsync(plr.UserId, Cash.Value)

game.Players.PlayerRemoving:connect(function() data1:SetAsync(plr.UserId, Cash.Value) end) end)

1 comment

1

Cash is not defined in your PlayerRemoving event

1 answer

Is see your problem: Cash is a local variable in your playeradded event, so it will return a nil value if it is called in your playerremoving function (it's making a new variable and setting it to nil). To fix this, just revise your script from saying

local Cash = Instance.new("IntValue")

And make it say

Cash = Instance.new("IntValue")

This makes the variable global.

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