I made this Datastore for my points system and it’s been working lately until now when I got an error in the console, can anyone help?
Script:
local DS = game:GetService("DataStoreService")
local PointsStore = DS:GetDataStore("Points")
local success, Error = pcall(function()
data = PointsStore:GetAsync(player.UserId.."Points")
end)
if success then
points.Value = data
else
warn(Error)
end
Error:
19:51:04.575 - 502: API Services rejected request with error. HTTP 403 (Forbidden)
First, do what @sjr04 said, then change it to this:
local DS = game:GetService("DataStoreService")
local PointsStore = DS:GetDataStore("Points")
local data
local success, Error = pcall(function()
data = PointsStore:GetAsync(player.UserId.."-Points")
end)
if success then
points.Value = data
else
warn(Error)
end
Your points variable always points to a StringValue instance. But you are comparing the reference against 0. points ~= 0 always evaluates to true. You meant points.Value ~= 0
It seems Its fixed when I made it a IntValue. But I tried to change my value via explorer then I stopped the test then joined again and it didn’t save.
local DS = game:GetService("DataStoreService")
local data
local PointsStore = DS:GetDataStore("Points")
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
if points ~= 0 then
points.Value = 0
end
playerStats[player] = leaderstats
local success, Error = pcall(function()
data = PointsStore:GetAsync(player.UserId.."-Points")
end)
if success then
points.Value = data
else
warn(Error)
end
local DS = game:GetService("DataStoreService")
local data
local PointsStore = DS:GetDataStore("Points")
local playerStats = {}
group = script.GroupID.Value
default = script.DefaultRank.Value
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Model", player)
leaderstats.Name = "leaderstats"
local grouprank = Instance.new("StringValue", leaderstats)
grouprank.Name = "Rank"
local rank = player:GetRoleInGroup(group)
if rank ~= "Guest" then
grouprank.Value = rank
else
grouprank.Value = default
end
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
if points ~= 0 then
points.Value = 0
end
playerStats[player] = leaderstats
local success, Error = pcall(function()
data = PointsStore:GetAsync(player.UserId.."-Points")
end)
if success then
points.Value = data
else
warn(Error)
end
end)
Are you running this code on a group game that you have build access to? If so, try publishing it onto your profile, keeping it private and testing it there to see if your error goes away. I ran into this issue a while back and for some reason even though I had edit access for the game, I couldn’t access data stores.
pcalling the code is a good idea in general, but it won’t fix your underlying issue, it will only mask the side-effects, creating a nasty data loss bug if not handled properly.