What do you want to achieve?
Have a function able to read a self.value variable.
What is the issue?
It looks like a function in an oop-based module script cannot read a self.value variable.
What solutions have you tried so far?
I’ve tried re-scripting it, reading my past work, and comparing them. It’s confusing and I don’t know what I did wrong.
Here is a preview of the oop-based module:
function BoxinModule.new(gloves, config)
--Default Variables
local self = {}
setmetatable(self, BoxinModule)
self.cameras = require(script:WaitForChild("CameraModule"))
--Player Variables
self.locPlr = game.Players.LocalPlayer
--Character Variables
self.character = self.locPlr.Character or self.locPlr.CharacterAdded:Wait()
self.humanoid = self.character:WaitForChild("Humanoid")
--Variables
self.BoxGloves = gloves
self.BoxConfig = require(config)
self.charStates =
{
idle = false,
hopping = false,
}
return self
end
function BoxinModule:PlayRandomJump()
local pick = math.random(1, 6)
local clone = script.JumpSounds:FindFirstChild(pick):Clone()
clone.Parent = self.character:FindFirstChild("Torso") --Here it can't read "self.character" Err Code: **attempt to index nil with 'FindFirstChild'**
clone:Destroy()
end
return BoxinModule
function BoxinModule:PlayRandomJump()
local pick = math.random(1, 6)
local clone = script.JumpSounds:FindFirstChild(pick):Clone()
clone.Parent = self.character:FindFirstChild("Torso")
clone:Destroy()
end
function BoxinModule:Hop(direction)
BoxinModule:PlayRandomJump()
--BoxinModule:SwitchCharState("hopping")
if direction then
else
end
wait(3)
--BoxinModule:SwitchCharState("idle")
end
function BoxinModule:PlayRandomJump()
local pick = math.random(1, 6)
local clone = script.JumpSounds:FindFirstChild(pick):Clone()
clone.Parent = self.character:FindFirstChild("Torso")
clone:Destroy()
end
function BoxinModule:Hop(direction)
self:PlayRandomJump()
--BoxinModule:SwitchCharState("hopping")
if direction then
else
end
wait(3)
--BoxinModule:SwitchCharState("idle")
end