Getting “attempt to call a nil value” and “Requested module experienced an error while loading” errors.
Reason being char(Character) being nil for some reason and I can’t figure out how to fix the problem
HandleBasket Module Code:
local basket = {}
local basketMT = {__index = basket}
local events = game.ReplicatedStorage:WaitForChild("Events")
local function init(self)
self.joint = Instance.new("Motor6D")
self.joint.Part0 = self.hand
self.joint.Parent = self.char
self.humanoid.Died:Connect(function()
self.isAlive = false
self:unequip()
end)
end
function basket.new(char)
local self = {}
self.humanoid = char:WaitForChild("Humanoid")
self.hand = char:WaitForChild("hand")
self.isEquipped = false
self.isAlive = true
init(self)
return setmetatable(self, basketMT)
end
function basket:equip(repBasket)
if (not repBasket) then
print("not basket")
self:unequip()
return
end
if self.isAlive == false then end
if self.isEquipped == true then self:unequip() end
print(self.isEquipped)
print("equip")
events.Setup:FireServer(repBasket)
self.settings = require(repBasket:WaitForChild("Settings"))
self.isEquipped = true
end
function basket:unequip()
print("unequip")
self.isEquipped = false
if self.basket then self.basket:Destroy() end
end
function basket:click()
end
basket:new()
return basket
Controls LocalScript Code:
local caService = game:GetService("ContextActionService")
local repStorage = game.ReplicatedStorage
local plr = game.Players.LocalPlayer
local char = plr.Character
local basket = Instance.new("ObjectValue")
basket.Value = repStorage.Baskets.PicnicBasket
basket.Parent = plr
local hB = require(repStorage.Modules.HandleBasket)
local basket = hB.new(char)
local function equipBind(actionName, inputState, inputObject)
if (inputState == Enum.UserInputState.Begin) then
basket:equip(basket.Value)
print("equipbind")
end
return Enum.ContextActionResult.Pass
end
local function clickBind(actionName, inputState, inputObject)
if (inputState == Enum.UserInputState.Begin) then
--basket:click();
end
return Enum.ContextActionResult.Pass
end
caService:BindAction("equip", equipBind, false, Enum.KeyCode.F, Enum.KeyCode.ButtonR1)
caService:BindAction("click", clickBind, false, Enum.UserInputType.MouseButton1)