Applying DataStore Data To Player Isn't Working

  1. What do you want to achieve? Keep it simple and clear!

Hello everyone, I have a script that saves if the player has gotten certain items and saves them as bool and int values. Once those bool and int values have been saved, I want it to duplicate the tools and put them into the player’s backpack. I’m pretty stumped here.

  1. What is the issue? Include screenshots / videos if possible!

I try to use the saved values to duplicate the tools into the player’s backpack. It’s not working and I don’t know what to do. The values also save across my game, as I have places under the actual game. Also for some reason, the int values don’t save across the places.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried to look across the dev forum but I can’t seem to find any solution. I’ve also tried printing out stuff to see if the script reads it, but it doesn’t output any print statements.

Place #1 Server Script, trying to apply the saved data.
This data gets saved, except the int values, which are the P9Ammo and P9MaxAmmo. Those int values are in the player’s backpack under a tool.

local weaponParts = game.ReplicatedStorage.PlayerData.GotWeaponParts
local gotArmor = game.ReplicatedStorage.PlayerData.GotArmor
local savedP9Ammo = game.ReplicatedStorage.PlayerData.P9Ammo
local savedP9MaxAmmo = game.ReplicatedStorage.PlayerData.P9MaxAmmo

local modelWeaponParts = game.ReplicatedStorage.PlayerData.Tools["Weapon Parts"]
local modelFlashDrive = game.ReplicatedStorage.PlayerData.Tools.FlashDrive

local currentP9Ammo = game.StarterPack.P9.Ammo
local currentP9MaxAmmo = game.StarterPack.P9.MaxAmmo
local currentFlashDrive = game.ReplicatedStorage.FlashDrive
local armorEquipped = game.ReplicatedStorage.ArmorEquip

players.PlayerRemoving:Connect(function(Player)
	savedP9Ammo.Value = currentP9Ammo.Value
	savedP9MaxAmmo.Value = currentP9MaxAmmo.Value
	gotArmor.Value = armorEquipped.Value
	savedFlashDrive.Value = currentFlashDrive.Value
end)

Place #2 This takes the saved data from the same DataStore and applies tries to apply it to the player once they join the place. The bool and int values are saved under Replicated Storage, but the int values don’t get saved. This is also a server script in ServerScriptService under a folder called PlayerDataScripts.

local players = game:GetService("Players")

local savedFlashDrive = game.ReplicatedStorage.PlayerData.GotFlashDrive
local weaponParts = game.ReplicatedStorage.PlayerData.GotWeaponParts
local gotArmor = game.ReplicatedStorage.PlayerData.GotArmor
local savedP9Ammo = game.ReplicatedStorage.PlayerData.P9Ammo
local savedP9MaxAmmo = game.ReplicatedStorage.PlayerData.P9MaxAmmo

local currentP9Ammo = game.StarterPack.P9.Ammo
local currentP9MaxAmmo = game.StarterPack.P9.MaxAmmo
local currentFlashDrive = game.ReplicatedStorage.FlashDrive
local armorEquipped = game.ReplicatedStorage.ArmorEquip

local modelWeaponParts = game.ReplicatedStorage.PlayerData.Tools["Weapon Parts"]
local modelFlashDrive = game.ReplicatedStorage.PlayerData.Tools.FlashDrive

players.PlayerAdded:Connect(function(Player)
	print("The player have been added")
	if savedP9Ammo.Value > 18 then
		savedP9Ammo.Value = currentP9Ammo.Value
	end
	
	if savedP9MaxAmmo.Value > 18 then
		savedP9MaxAmmo.Value = currentP9MaxAmmo.Value
	end
	
	if weaponParts.Value == true then
		print("Weapon Parts should have been added")
		local clonedWeaponParts = modelWeaponParts:Clone()
		clonedWeaponParts.Parent = Player.Backpack
	end
	
	if currentFlashDrive.Value == true then
		print("Armor should have been added")
		local clonedFlashDrive = modelFlashDrive:Clone()
		clonedFlashDrive.Parent = Player.Backpack
	end
	
	if gotArmor.Value == true then
		print("Armor should have been added")
		armorEquipped.Value = true
	end
end)

This is the output for Place #2
image

(If you want the DataStore scripts, I will edit this post and post it up)