The reason why I am using a Module is because it’s just easier for what I’m doing lol but here’s my script and error.
local AddItem = {}
local WeldDataModule = require(game.ReplicatedStorage.Modules.KitchenModules.WeldDataModule)
local NextPossibleAddItemTime = 0.5
function AddItem.ColdDrinkCupLid(Player)
local ItemPath = workspace.Workspace.Cafe.Kitchen.Items.ColdDrinkCupLids
local ColdDrinkCupLid = game.ReplicatedStorage.Items.ColdDrinkCupLid
local Sound = ItemPath.TouchPart.Use
local Item = Player:FindFirstChildOfClass("Tool")
local Active = ItemPath:GetAttribute("Active")
if Active == true then
ItemPath:SetAttribute("Active", false)
Item:SetAttribute("CanBeUsed", false) --this is the line that erroring out
Item:SetAttribute("ItemName", "ColdDrinkCup_Lid")
local Lid = ColdDrinkCupLid:Clone()
Lid.Parent = Item.Handle
local Weld = Instance.new("Weld")
Weld.Parent = Item.Handle
Weld.Part0 = Item.Handle
Weld.Part1 = Item.Handle.ColdDrinkCupLid
Weld.C0 = CFrame.new(WeldDataModule.ColdDrinkCupLid)
wait(NextPossibleAddItemTime)
ItemPath:SetAttribute("Active", true)
end
end
return AddItem
It seems this is nil. Perhaps you forgot to send the character in the parameter or something? If you are equipping the tool, the tool is in the character. Otherwise, you have the tool in Player.Backpack.
This extendedly changes the approach of writing the code and does not solve the actual problem. Perhaps you are too invested in the stylistic ways of programming?
It is worth a supplementary detail, but it does not satisfy the actual problem in question.
local ch, tool;
ch = Player.Character or Player.CharacterAdded:Wait(); tool = ch:FindFirstChildOfClass("Tool")
if tool then
-- do stuff with the tool
end