I'm making a murder game and I'm trying to make it where players can purchase items (skins, effects, etc.), but the way I want the weapons (there class name being tools) to save is by using a DataStore in a value named 'Inventory'. But the script I made doesn't save the tools. The error I get is: "ServerScriptService.Saveinv:18: bad argument #3 to 'Value' (string expected, got nil) Stack Begin Script 'ServerScriptService.Saveinv', Line 18 Stack End" The script is:
local ds = game:GetService("DataStoreService"):GetDataStore("stats")
local stats={"Murderer","Knife","Revolver"}
game.Players.PlayerAdded:connect(function(plyr)
local a=Instance.new("BoolValue")
a.Parent=plyr
a.Name="Inventory"
for i=1,#stats do
local stat=Instance.new("StringValue")
stat.Parent=a
stat.Value= "Default"
stat.Name=stats[i]
if a:WaitForChild("Murderer") then a.Murderer.Value = "Identify"
end
end
local child=plyr.Inventory:GetChildren()
for i=1, #child do
child[i].Value=ds:GetAsync(plyr.userId..child[i].Name)
end
local wep = a:GetChildren()
if wep.ClassName == "Tool" then
wep=ds:GetAsync(plyr.userId.child.wep.Name)
end
end)
game.Players.PlayerRemoving:connect(function(plyr)
local child=plyr.Inventory:GetChildren()
for i=1, #child do
child[i].Value=ds:SetAsync(plyr.userId..child[i].Name,child[i].Value)
end
end)
I'm not the best at scripting nor am I great with DataStores so all help is appreciated. EDIT: The StringValues Murderer, Knife, and Revolver are the skins or abilities equipped.

1 comment
(I know this has been awhile) The -local wep = inv:GetChildren()- was supposed to save the weapon that you bought, but I think instead of using a tool I will just use values and when your inventory GUI shows it will just get the item from the value. So thank you for the help!