Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Resolved] OOP Functions Not Inherited?

Asked by
SWX253 2
3 years ago
Edited 3 years ago

I'm currently writing some OOP code for doors. For some reason, the newly created door objects return nil when they call a function of the LevelDoor class. The functions and constructor are both stored within a module script whilst a function is being called from a serverscript. I've tried calling another function and nil is returned all the same. It appears the functions aren’t being inherited. How can this be resolved and what’s causing the issue?

Error

ServerScriptService.ServerModules.LevelDoorLib Test:16: attempt to call a nil value

Module Script

01local LevelDoor = {}
02LevelDoor._index = LevelDoor
03 
04-- Services
05local Players = game:GetService("Players")
06 
07-- Main
08function LevelDoor.new(door)
09    local NewLevelDoor = {}
10    --[ Properties
11    NewLevelDoor.Door = door.Head
12    NewLevelDoor.Config = require(door.LevelDoorConfig)
13    NewLevelDoor.AreaName = NewLevelDoor.Config.AreaName or "Realm"
14    NewLevelDoor.RequiredLevel = NewLevelDoor.Config.RequiredLevel or 0
15    NewLevelDoor.GUI = door.BillboardGui.TextLabel
View all 45 lines...

Serverscript

01-- Services
02local ServerScriptService = game:GetService("ServerScriptService")
03 
04-- Modules
05local LevelDoorLib = require(ServerScriptService.ServerModules.LevelDoorLib)
06 
07-- Declarations
08local NewLevelDoor = LevelDoorLib.new(workspace.LevelDoorHolder.LevelDoor2)
09local LevelDoor2 = workspace.LevelDoorHolder.LevelDoor2.Head
10 
11-- Main
12print(LevelDoorLib)
13print(NewLevelDoor)
14 
15LevelDoor2.Touched:Connect(function(hit)
16    NewLevelDoor:OnTouch(hit)
17end)
0
mind showing parts of the explorer? or NGC4637 602 — 3y
0
Sure SWX253 2 — 3y

1 answer

Log in to vote
0
Answered by
SWX253 2
3 years ago

The reason the functions weren’t inherited was I mistyped "__index” as ”_index”.

Ad

Answer this question