I need help with a custom inventory system, here is how it works, the player can collect certain parts which are the items for the inventory by clicking them, the items are stored inside of a folder called items (the folder is in the workspace) when the items are collected, they appear in the player’s inventory gui and they are removed from the workspace, when you click one of the items in the gui three imagebuttons appear and you have the options to drop the item, (and all items have a intvalue called drop in them) the option to consume, (if the consume intvalue is in the item and not all items have the consume intvalue), or you can press cancel (and all items have a cancel intvalue inside), so if the drop imagebutton is pressed it drops the item in the workspace at the player’s feet and removes the item from their inventory or if the consume button is pressed it gives the player health and removes the item or you can click the cancel imagebutton and the three imagebuttons will disappear and only the item will show, the items can save and the player will still have the items when they rejoin.
the issue im having is the player cannot drop items again after they have rejoined the game so basically saved items cannot be dropped, what could the problem be or what is something that could help solve my issue? here are the local and server scripts, any help?
the player can pick up an item and can drop it again if it is not a saved item:
https://gyazo.com/680727ff32e422099bc8b0c717415a82
the issue: the player cannot drop saved items:
https://gyazo.com/4aaa47fecb73fa89f01fb14f1c56cd6a
Server Script:
local DS = game:GetService("DataStoreService"):GetGlobalDataStore("Data")
local Version = 2
local Data = {}
local Max_Slots = 28
local function Save(Player)
local Player_Data = Data[Player.Name]
local Key = Player.UserId .. " - " .. Version
DS:SetAsync(Key, Player_Data)
end
game.Players.PlayerAdded:Connect(function(Player)
local Key = Player.UserId .. " - " .. Version
local Async = DS:GetAsync(Key)
local Player_Data = {}
if Async ~= nil then
Player_Data = Async
end
Data[Player.Name] = Player_Data
local Player_Data = Data[Player.Name]
game.ReplicatedStorage:WaitForChild("Inventory"):FireClient(Player, Player_Data)
Player.CharacterAdded:Connect(function(Character)
game.ReplicatedStorage:WaitForChild("Inventory"):FireClient(Player, Player_Data)
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
Save(Player)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
Save(Player)
end
end)
for _, Item in pairs(game.Workspace:WaitForChild("Items"):GetChildren()) do
local Collected = Item:WaitForChild("Collected")
Item:WaitForChild("CD").MouseClick:Connect(function(Player)
if Collected.Value == false and Player ~= nil then
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid ~= nil and Humanoid.Health > 0 and Player ~= nil then
local Player_Data = Data[Player.Name]
if Player_Data ~= nil and #Player_Data < Max_Slots then
Collected.Value = true
local Options = {}
for _, Object in pairs(Item:GetChildren()) do
if Object:IsA("IntValue") == true then
Options[Object.Name] = Object.Value
end
end
local Data = {
Name = Item.Name;
Options = Options
}
table.insert(Player_Data, Data)
game.ReplicatedStorage:WaitForChild("Inventory"):FireClient(Player, Player_Data)
Item.Parent = script
end
end
end
end)
end
game.ReplicatedStorage:WaitForChild("Inventory").OnServerEvent:Connect(function(Player, Info)
local Player_Data = Data[Player.Name]
if Player_Data ~= nil then
local Index, Item, Type = Info.Index, Info.Item, Info.Type
for Index_, Data in pairs(Player_Data) do
if Index == Index_ and Data.Name == Item then
if Type == "Drop" then
table.remove(Player_Data, Index)
local Object = script:FindFirstChild(Item)
local Character = Player.Character
if (Object ~= nil) then
local HRP = Player.Character.HumanoidRootPart
Object.CFrame = Character:GetPrimaryPartCFrame() * CFrame.new(0, -4, -2)
Object.Parent = game.Workspace:WaitForChild("Items")
Object:WaitForChild("Collected").Value = false
end
elseif Type == "Consume" then
table.remove(Player_Data, Index)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
if Humanoid.Health < Humanoid.MaxHealth then
Humanoid.Health = Humanoid.Health + Data.Options.Consume
end
end
break
end
end
game.ReplicatedStorage:WaitForChild("Inventory"):FireClient(Player, Player_Data)
end
end)