I'm working on a simple "find x and return" type quest but I'm having issues. I have two module scripts, one for the clickable part and one for a table. In the table it recognizes the player has an existing tool when the part is clicked, but won't recognize my return statement. The item giver script is supposed to run the table inventorydata function (which it does properly) and recognizes the player has an existing tool, but it will not return the function. Here's the code:
Table script
local ItemModule = {}
local itemFolder = game.ServerStorage.ItemStorage
ItemModule.ItemStorage = { -- For cloning into the players backpacks in item module's scripts.
["Sample"] = itemFolder.Sample
}
function ItemModule.inventoryData(backpack, starterGear) -- Sharing variables between this script and all item modules scripts.
ItemModule.BackpackItems = {
["BackpackSample"] = backpack:FindFirstChild("Sample"),
["StarterSample"] = starterGear:FindFirstChild("Sample")
}
local item = ItemModule.BackpackItems
if (item["BackpackSample"] ~= nil) or (item["StarterSample"] ~= nil) then
print("item already exists!") -- this prints out, but the return doesn't work.
return
end
end
return ItemModule
Item giver script
local ItemModule = {}
local module = require(game.ServerStorage.ItemTable)
local itemFolder = game.ServerStorage.ItemStorage
local item = itemFolder.Sample -- Chosen item, makes creating other scripts easier. (because it uses this single variable!)
function ItemModule.itemFunc(player)
local backpack = player.Backpack
local starterGear = player.StarterGear
local check = false
module.inventoryData(backpack, starterGear) -- inventorydata function runs here.
local itemClone = item:Clone()
local itemCloneBackup = item:Clone()
itemClone.Parent = player.Backpack -- Clones to player's backpack.
itemCloneBackup.Parent = player.StarterGear -- Clones to player's StarterGear (so if they die, they'll still have it).
end
return ItemModule

2 comments
Thanks! I figured out a way to solve it about 2 minutes ago but I'll use your solution since it's a better method. I appreciate the explanation on returns, I never really understood them before.
Sadly it didn't work so I'll just use the solution I found, by moving the cloning over to the table script.