DataStore not saving IntValue, I tried looking already

My problem is kind of simple but also not, as I’ve been trying to save this table which are full of Int and Bool values. For some reason, the bool values save but the int values don’t. Also the values are under a folder called PlayerData, except for the Int Values that I will show in a screenshot.
The Int Values are under a tool and the script is a server script in ServerScriptService.

Screenshot of the Player Data, under Replicated Storage
image

The code that saves the data. Note that the Int values are the Ammo and MaxAmmo. Also the flashdrive print statement doesn’t print out

--Data Store
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerData")

local players = game:GetService("Players")

local function save(player)
	local userID = player.UserId
	local key = "Player_"..userID
	
	local backpack = player:WaitForChild("Backpack")
	local tool = backpack:WaitForChild("P9")
	local P9Ammo = tool:WaitForChild("Ammo")
	local P9MaxAmmo = tool:WaitForChild("MaxAmmo")
	
	local playerData = {
		game.ReplicatedStorage.PlayerData.GotFlashDrive.Value;
		game.ReplicatedStorage.PlayerData.GotWeaponParts.Value;
		game.ReplicatedStorage.PlayerData.GotArmor.Value;
		P9Ammo.Value;
		P9MaxAmmo.Value;
		game.ReplicatedStorage.PlayerData.MaleFlag.Value;
		game.ReplicatedStorage.PlayerData.FemaleFlag.Value
	}

	local success, err = pcall(function()
		PlayerDataStore:SetAsync(key, playerData)
	end)

	if success then
		print("The data Have Been SAVED WOO")
		print("This is data flashdrive witherws: "..game.ReplicatedStorage.PlayerData.GotFlashDrive.Value)
	else
		print("Aw man, the data didn't save.")
		warn(err)
	end

end

local function onShutDown()
	task.wait(6)
end

local function setUp(player)
	local userID = player.UserId
	local key = "Player_"..userID
	
	local backpack = player:WaitForChild("Backpack")
	local tool = backpack:WaitForChild("P9")
	
	local flashDrive = game.ReplicatedStorage.PlayerData.GotFlashDrive
	local weaponParts = game.ReplicatedStorage.PlayerData.GotWeaponParts
	local gotArmor = game.ReplicatedStorage.PlayerData.GotArmor
	local P9Ammo = tool:WaitForChild("Ammo")
	local P9MaxAmmo = tool:WaitForChild("MaxAmmo")
	local male = game.ReplicatedStorage.PlayerData.MaleFlag
	local female = game.ReplicatedStorage.PlayerData.FemaleFlag

	local data
	local success, err = pcall(function()
		data = PlayerDataStore:GetAsync(key)
	end)

	if success and data then
		flashDrive.Value = data[1]
		weaponParts.Value = data[2]
		gotArmor.Value = data[3]
		P9Ammo.Value = data[4]
		P9MaxAmmo.Value = data[5]
		male.Value = data[6]
		female.Value = data[7]
	else
		print("Uh oh... Player didnt save.")
	end
end

players.PlayerAdded:Connect(setUp)

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		local success, err  = pcall(function()
			save(player) -- Save the data
		end)

		if success then
			print("Data has been saved")
		else
			print("Data has not been saved!")
		end
	end
end)

players.PlayerRemoving:Connect(function(player)
	local success, err = pcall(function()
		save(player)
	end)

	if success then
		print("Omg you're so smart, data saved.")
	else
		print("Data didn't save")
	end
end)

Are you setting IntValue.Value on the client? The server may not be able to see the changes.

Oh, you are correct. A local Script is changing the ammo values. Thank you for telling me cause I never noticed for the longest time.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.