i tried everything but it still wont work it says a error at line 24 of the script
here is the script :
local ItemModule = game.ReplicatedStorage.Itemdata
local Itemdata = require(ItemModule)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
waitTimer = 0.06
function randomitem(player)
local ROLL = script.Parent.Parent.Rolls
ROLL.WonItem.Visible = false
ROLL.Visible = true
for i = 1,20 do
wait(waitTimer)
waitTimer = waitTimer + 0.03
local picked = (Itemdata.data[math.random(1, #Itemdata.data)])
ROLL.RollImage.Image = "rbxassetid://"..picked.ImageID
if i == 20 then
ROLL.WonItem.Visible = true
ROLL.WonItem.Text = "U got : ".. picked.Name
local itemId = picked.ItemID
print(itemId)
local inventoryStore = DataStore2("Inventory", player)
inventoryStore:Update(function(currentTable)
if (currentTable[itemId]) then
currentTable[itemId] = currentTable[itemId] + 1
else
currentTable[itemId] = 1
end
return currentTable
end)
end
end
waitTimer = 0.06
end
script.Parent.MouseButton1Click:Connect(randomitem)
currentTable is nil. Does the function passed to Update take an argument? Or is the argument nil because you haven’t set it before? Check that it’s not nil before you do stuff with it.
its not nil because it prints the number 5 because how i did this system was set items on ItemId so when i change a item name there is no data lose for players
Then currentTable is nil. Or your can print currentTable to show that I’m wrong, but I’m fairly confident here. I don’t use DS2 so I couldn’t help, but I do think that you might need to add a default value to save in case currentTable is nil.
umm yeah eh eh eh how could i say this umm there was a miss typo in the datastore2 and thats why it wasnt saving the whole time eh eh oopsie sorry for wasting your guys time