I wanted to make an inventory system,i put the whole script in there but when i run it it says “Argument 1 missing or nil”
How can i fix it?
The error in the script is only in the drop event,but i put the whole script,its marked down though.
game.Players.PlayerAdded:Connect(function(player)
local PlrInv = Instance.new("Folder")
PlrInv.Name = (player.UserId .. player.Name)
PlrInv.Parent = workspace.Inventories
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage.Inv.Pickup.OnServerEvent:Connect(function(player,item)
local HRP = player.Character:WaitForChild("HumanoidRootPart")
local MaxDistance = player.PlayerGui.PickupGui.MaxDistance
if (HRP.Position - item.Position).Magnitude < MaxDistance then
if workspace.Inventories[player.UserId .. player.Name]:FindFirstChild(item.Name) then
workspace.Inventories[player.UserId .. player.Name][item.Name].Value += 1
player.PlayerGui.Inventory.Frame[item.Name].ItemCount.Text = workspace.Inventories[player.UserId .. player.Name][item.Name].Value
item:Destroy()
elseif not workspace.Inventories[player.UserId .. player.Name]:FindFirstChild(item.Name) then
local NewItem = Instance.new("IntValue",workspace.Inventories[player.UserId .. player.Name])
NewItem.Name = item.Name
item:Destroy()
NewItem.Value = 1
local NewItemGui = ServerStorage.Assets.Gui.Template:Clone()
NewItemGui.Name = item.Name
NewItemGui.ItemCount.Text = 1
NewItemGui.ItemName.Text = item.Name
NewItemGui.Parent = player.PlayerGui.Inventory.Frame
end
end
end)
ReplicatedStorage.Inv.Drop.OnServerEvent:Connect(function(player,item) -- When the player presses the drop button it fires
local playerinv = workspace.Inventories[player.UserId .. player.Name] -- Gets the player inventory
if workspace.Inventories[player.UserId .. player.Name]:FindFirstChild(item.Name) then -- Error here
local itemi = playerinv[item.Name]
if itemi.Value > 0 then
itemi.Value -= 1
local DropItem = ServerStorage.Items[item.Name]:Clone()
DropItem.Parent = workspace
DropItem.Position = player.Character.HumanoidRootPart.Position + Vector3.new(2,3,0)
end
end
end)
Thanks in advance.