Hello, i have an if statement that gets a value from a module script and checks to see if it is false. When the item is dropped it goes through the whole loop and prints all the values.
Output:
code:
if v.Dropable == false then
print(v.Dropable)
if item.Value > 0 then
item.Value = item.Value - 1
local itemClone = items:FindFirstChild(itemName):Clone()
print(itemTable)
table.insert(itemTable, itemClone)
for i, part in pairs(itemTable) do
PhysicsService:SetPartCollisionGroup(part, "ItemGroup")
end
itemClone.Anchored = false
local itemNotCloneName = items:FindFirstChild(itemClone.Name)
print(itemNotCloneName)
itemClone.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.LookVector * 4
itemClone.Parent = game.Workspace
return true
else
return false
end
else
print("Nope")
end
It prints nope 2x and the rest of the values once. There is only 1 nope statement in the if stament.
DropItem.OnServerInvoke = function(player, itemName)
for i, v in pairs(itemsmodule) do
local Inventory = player.Inventory
local item = Inventory:FindFirstChild(itemName)
if item then
if v.Dropable == false then
print(v.Dropable)
if item.Value > 0 then
item.Value = item.Value - 1
local itemClone = items:FindFirstChild(itemName):Clone()
print(itemTable)
table.insert(itemTable, itemClone)
for i, part in pairs(itemTable) do
PhysicsService:SetPartCollisionGroup(part, "ItemGroup")
end
itemClone.Anchored = false
local itemNotCloneName = items:FindFirstChild(itemClone.Name)
print(itemNotCloneName)
itemClone.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.LookVector * 4
itemClone.Parent = game.Workspace
return true
else
return false
end
else
print("Nope")
end
end
end
end
When the item gets an input then it will send a event. itemsmodule is the module with my items which is set up like:
local ItemsModule = {
["Coal"] = {
Name = "Coal",
Picture = 137510460,
Dropable = true,
};
return ItemsModule
Haven’t found the cause of the error, as everything looks pretty good to me, but in your module theres a mistake that I can see, I don’t know if its intentional for the code but its missing a closing bracket for the ItemsModule table.
But I quite don’t understand the point of looping through the itemsModule table for dropping the item, because like you check if the Current item in the table is Droppable not the item that the user wants to drop specifically. In other words what I would do in a function like this is:
if not itemsmodule[itemName]["Droppable"] then return end
so it would check if the item is droppable, if not then it will end the function at that point itself, and then I would continue the checking and removing item from his inventory, cloning etc.