I’m having some issue with this script. It’s being used to save the players Gold and Level. Whenever I join the game the set value for the level is 1 and it’s not making it one its staying as 0 I have HTTP enabled along with all the other things but It’s still not working. I’m getting zero errors and all of my prints aren’t even showing up on the output. It’s in a Script located in ServerScriptStorage
local DataStoreService = game:GetService(“DataStoreService”)
local LevelDataStore = DataStoreService:GetDataStore(“Level”)
local GoldDataStore = DataStoreService:GetDataStore(“Gold”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”
local level = Instance.new("NumberValue", leaderstats)
level.Name = "Level"
level.Value = 1
local gold = Instance.new("NumberValue", leaderstats)
gold.Name = "Gold"
gold.Value = 0
local levelData
local goldData
local success, errorMessage = pcall(function()
local levelData = LevelDataStore:GetAsync(player.UserId)
local goldData = GoldDataStore:GetAsync(player.UserId)
end)
if success then
level.Value = levelData
gold.Value = goldData
else
level.Value = 1
gold.Value = 0
print(player.Name " : ".. player.UserId "'s DATA WAS NOT FOUND!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
LevelDataStore:SetAsync(player.leaderstats.Level.Value, player.UserId)
GoldDataStore:SetAsync(player.leaderstats.Gold.Value, player.UserId)
end)
if success then
print(player.Name .. " : "..player.UserId .."'s DATA HAS BEEN FOUND!")
end
end)