I’ve been having this issue where I want items to continuously add to the value say you have one sword then instead of making another sword it just adds to the value of that one sword.
How do you save data? In a JSON string I assume.
That’s not even my issue, my guy
thing.Value = "sword1"
thing.Value = thing.Value..",sword2"
then to get the strings:
local ownedItems = thing.Value:split(",")
print(ownedItems[2])
-- which becomes: ownedItems = {"sword1","sword2"}
-- this may return blank values so either make sure to loop and check then remove them/ensure the value is never just " " before adding something new to it, i.e:
if thing.Value == " " then
thing.Value = "sword1"
else
thing.Value = ownedItems.Value..",sword2"
end
I think this might be what you mean, if not then elaborate further in a reply and I’ll do my best to help
sorry if this is messy, typing it here instead of on Studio
Sorry but, uh let me have you take a look at my loading script for the inventory
local function UpdateInventory(Default)
local tab = InventoryStore:GetTable(Defaults)
for i,v in pairs(tab) do
if Inventory:FindFirstChild(v) then
else
print("Adding New Item!")
local item = Instance.new("NumberValue")
item.Name = v[1]
item.Value = v[2]
item.Parent = Inventory
end
end
end
If theres already an item I want to make the value + 1
local tab = InventoryStore:GetTable(Defaults)
for i,v in pairs(tab) do
if Inventory:FindFirstChild(v) then
Inventory[v][1].Value = Inventory[v][1].Value + 1
else
print("Adding New Item!")
local item = Instance.new("NumberValue")
item.Name = v[1]
item.Value = v[2]
item.Parent = Inventory
end
end
end
you mean like this? it +1s if it is found (remember FFC takes a string so if v isn’t a string it FFC won’t work)
So basically the v is the name of item inside of the table
Edited version should be right, lemme know if it works or not
RATS, its not working man!! Fridge what could be wrong
Show me your output, might’ve done something wrong with the indexing
Im picking up the item but its value is staying at 1! sadly also their is nothing in the output
Here is the script when I pick up the item
for i,v in ipairs(Pickupables.Weapons) do
if item and item.Name == v and (item.PrimaryPart.Position - humrp.Position).Magnitude <= 5 and item then
if Inventory:FindFirstChild(item.Name) then
for i,v in pairs(Inventory:GetChildren()) do
if v.Name == item.Name then
print(v.Name)
end
end
elseif not Inventory:FindFirstChild(item.Name) then
local Put = Instance.new("NumberValue")
Put.Name = item.Name
Put.Value = 1
print("The player has just picked up a "..item.Name)
table.insert(InventoryTable, {Put.Name, Put.Value})
InventoryStore:Set(InventoryTable)
item:Destroy()
print("Testing")
end
end
end
end)
You’re setting the value to 1, not incrementing it by 1
Put.Value = Put.Value + 1
Dude thats when the player doesnt already have the item in their inventory!
What is item
set as?
Why are you searching for item
in two different ways? There’s also no modification of the IntValues anywhere
if Inventory:FindFirstChild(item.Name) then
Inventory[item.Name].Value = Inventory[item.Name].Value + 1 -- this would be an IntValue, correct?
Yes, Ghnarwhal that works but it doesnt save at all, Ive tried that
I have to update it through the InventoryUpdate function not through there, thats where I just save it