Can anyone tell me why datastore is not working? I have literally tried 3 different scripts none of them works I even paid scripter to make for me a datastore but doesn’t work either anyone know why? I also have double check the game permissions for API Service its ON
this script is made by the guy i hired
local databaseService = game:GetService("DataStoreService")
local database = databaseService:GetDataStore("Leaderstats")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local Leaderstats = player:WaitForChild("Leaderstats")
local rank = leaderstats:WaitForChild("Rank")
local level = Leaderstats:WaitForChild("Level")
local xp = Leaderstats:WaitForChild("XP")
pcall(function()
level.Value = database:GetAsync(player.UserId.."-leaderstatsLevel1") or 1
rank.Value = database:GetAsync(player.UserId.."-leaderstatsRank1") or "Private"
xp.Value = database:GetAsync(player.UserId.."-leaderstatsXp1") or 0
end)
end)
while wait(120) do
for _,player in pairs(game.Players:GetPlayers()) do
pcall(function()
database:SetAsync(player.UserId.."-leaderstatsRank1", player.leaderstats.Rank.Value)
database:SetAsync(player.UserId.."-leaderstatsLevel1", player.Leaderstats.Level.Value)
database:SetAsync(player.UserId.."-leaderstatsXp1", player.Leaderstats.XP.Value)
end)
end
end
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
database:SetAsync(player.UserId.."-leaderstatsRank1", player.leaderstats.Rank.Value)
database:SetAsync(player.UserId.."-leaderstatsLevel1", player.Leaderstats.Level.Value)
database:SetAsync(player.UserId.."-leaderstatsXp1", player.Leaderstats.XP.Value)
end)
end)
and this one is made by me
local Webhook = "w"
local Https = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("LevelData")
game.Players.PlayerAdded:Connect(function(player)
local data
local success,errormsg = pcall(function()
data = DataStore:GetAsync('Player_'..player.UserId)
end)
local Level = player:WaitForChild("Leaderstats").Level
local XP = player:WaitForChild("Leaderstats").XP
local Rank = player:WaitForChild("leaderstats").Rank
if success then
if data then
Level.Value = data
XP.Value = data
Rank.Value = data
print(Rank.Value)
print(Level.Value)
print(XP.Value)
else
warn("Data Does not exist", data)
end
else
warn("Data could not be retrieved!", data)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormessage = pcall(function()
DataStore:SetAsync('Player_'..player.UserId,player:WaitForChild("Leaderstats").Level.Value)
DataStore:SetAsync('Player_'..player.UserId,player:WaitForChild("Leaderstats").XP.Value)
DataStore:SetAsync('Player_'..player.UserId,player:WaitForChild("leaderstats").Rank.Value)
end)
local failed = {
content = "Failed to save data, Player_"..player.UserId,
}
local work = {
content = "Successfully saved, Player_"..player.UserId,
}
if not success then
Https:PostAsync(Webhook,Https:JSONEncode(failed))
warn("Data could not be saved! Error:",errormessage)
return
elseif success then
Https:PostAsync(Webhook,Https:JSONEncode(work))
end
end)
the script i made only save Rank.Value but not Level and XP
