DataStoreService: AccessForbidden: Access forbidden. API: GetAsync, Data Store: LeaderSave
(LeaderSave is my DataStore)
Anytime a DataStore occurs an error and doesn’t success, I kick the player. But once the player rejoins, It becomes 250, instead of their original amount.
Leaderstats Script:
local dataStoreService = game:GetService("DataStoreService")
local DS = dataStoreService:GetDataStore("LeaderSave") -- LeaderSave
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
--------
local hexa = Instance.new("IntValue")
hexa.Name = "Hexa"
hexa.Value = 250 -- Always 100
hexa.Parent = leaderstats
-------
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
deaths.Parent = leaderstats
-------
print("Leaderstats Loaded!")
--------------------------------------------
local DeathsData, WinsData, HexaData
local success, errormessage = pcall(function()
DeathsData = DS:GetAsync("deaths-"..player.UserId)
WinsData = DS:GetAsync("wins-"..player.UserId)
HexaData = DS:GetAsync("hexa-"..player.UserId)
end)
if success then
print("Successful!")
deaths.Value = DeathsData
wins.Value = WinsData
hexa.Value = HexaData
else
warn("Failed To Load Data!")
player:Kick("Please rejoin. An error occured with your data")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DS:SetAsync("deaths-"..player.UserId, player.leaderstats.Deaths.Value)
DS:SetAsync("wins-"..player.UserId, player.leaderstats.Wins.Value)
DS:SetAsync("hexa-"..player.UserId, player.leaderstats.Hexa.Value)
end)
end)
game:BindToClose(function()
wait(2)
end)
Although I am skilled in the ability to sight read roblox script behavior, it is better practice for you to use print to find out if your code is working properly.
This while loop doesn’t make sense.
you have 3 pcall function calls but only the 3rd one will be checked if successful.
What I would do is delete this loop and change your earlier code to be in a for loop.
for i=1,7 do
local success, response = pcall(function()
DeathsData = DS:GetAsync("deaths-"..tostring(player.UserId))
WinsData = DS:GetAsync("wins-"..tostring(player.UserId))
HexaData = DS:GetAsync("hexa-"..tostring(player.UserId))
end)
if success then
print("Successful!")
deaths.Value = DeathsData
wins.Value = WinsData
hexa.Value = HexaData
break
end
end