So in my game, I've recently been working on a system to save the weapon you have equipped that works in the same script as my saving script for all the player's stats, but I'm using a stringvalue that keeps the name of the weapon equipped and looks for the name of the weapon in ReplicatedStorage. (I'm using stringvalues because datastores can't save objectvalues.) However, there's one problem. The saving doesn't work! Here's the script.
local DSService = game:GetService('DataStoreService'):GetDataStore('ZA3TestData')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('Folder', plr)
local savevalue1 = Instance.new('IntValue')
local savevalue2 = Instance.new('IntValue')
local savevalue3 = Instance.new('IntValue', plr)
local savevalue4 = Instance.new('IntValue')
local savevalue5 = Instance.new('StringValue', plr)
leaderstats.Name = 'leaderstats'
savevalue4.Parent = leaderstats
savevalue1.Parent = leaderstats
savevalue2.Parent = leaderstats
savevalue1.Name = 'Level'
savevalue2.Name = 'Prestige'
savevalue3.Name = "XP"
savevalue4.Name = "Kills"
savevalue5.Name = "SavedWeapon"
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue1.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
savevalue3.Value = GetSaved[3]
savevalue4.Value = GetSaved[4]
savevalue5.Value = GetSaved[5] or "Brick"
else
local NumbersForSaving = {savevalue1.Value, savevalue2.Value, savevalue3.Value, savevalue4.Value, savevalue5.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Level.Value, plr.leaderstats:FindFirstChild('Prestige').Value, plr.XP.Value, plr.leaderstats.Kills.Value, plr.SavedWeapon.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
Also, when I load the game with the script, this is the error I get:
ServerScriptService.Player Stats:28: bad argument #3 to 'Value' (string expected, got nil)
Thanks!

2 comments
All my weapons have a name because in my custom weapon hotbar GUI it shows the name of the weapon above the button to equip it, but I might just remove that for this. I'll see how it goes, thanks!
U could add a script to define every ID to a weapon. It's more securely then string value's.