so i found a script, took it and modified it, and uh it didn’t work
edit: here’s the error:
502: API Services rejected request with error. HTTP 403 (Forbidden)
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("playerData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Wins"
gold.Parent = leaderstats
local po = Instance.new("IntValue")
po.Name = "Points"
po.Parent = leaderstats
local data
local data2
local success, errormessage = pcall(function()
data = playerData:GetAsync(player.UserId.."Wins")
data2 = playerData:GetAsync(player.UserId.."Points")
end)
if success then
gold.Value = data
po.Value = data2
else
print("uh oh bad no save :(")
warn(errormessage) --error line
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
playerData:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value)
playerData:SetAsync(player.UserId.."-Points", player.leaderstats.Points.Value)
end)
if success then
print("YAJ SAVED")
else
print("uh oh bad no save :(") -- da error
warn(errormessage)
end
end)
Some people have had this problem before (HTTP 403 (Forbidden) - #9 by DarkContinuum), fixed by setting place to public. Could also be that you don’t have API Services Allowed.
In your saving part, you are saving using the key player.UserId…"-Wins", but in the loading, you did not put the -. You can either add the dash in the loading part or remove it in the saving.
The first parameter is a string value, if it has a -, it is a completely different value.
It would be saving with the key “00000-Wins” instead of “00000Wins”.
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("playerData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Wins"
gold.Parent = leaderstats
local po = Instance.new("IntValue")
po.Name = "Points"
po.Parent = leaderstats
local data
local data2
local success, errormessage = pcall(function()
data = playerData:GetAsync(player.UserId.."-Wins")
data2 = playerData:GetAsync(player.UserId.."-Points")
end)
if success then
gold.Value = data
po.Value = data2
else
print("uh oh bad no save :(")
warn(errormessage) --error line
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
playerData:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value)
playerData:SetAsync(player.UserId.."-Points", player.leaderstats.Points.Value)
end)
if success then
print("YAJ SAVED")
else
print("uh oh bad no save :(")
warn(errormessage)
end
end)
the kicking part is just for when your in studio, its probably some bug or something, im not 100% sure why.
you dont need to kick the player when they leave.