#Is there a way to get the script that is requiring a module?

1 messages · Page 1 of 1 (latest)

weak viper
#

I'm trying to get into the habit of using module scripts more often, and so for the enemy script I'm making at the moment (specifically working on pathfinding) I have the general stuff that multiple enemies will do stored in a module script, while each enemies specific stuff will be contained in their own server script.

However, for the pathfinding script, I need to get the humanoid of the enemy from the module script. Is there a way to do this cleanly? Am i using module scripts wrong? Any help is very much appreciated 🙏

#

-# My module side of things is a bit too long to post in its entirety, so ill condense it down a bit

Module Script

local Players = game:GetService("Players")
local Enemy = script.Parent
local humanoid = Enemy:WaitForChild("Humanoid")

function SetUp()
    local State = Instance.new("StringValue")
    State.Name = "State"
    State.Value = "Track"
    State.Parent = Enemy
end

local module = {
    SetUp()
    
}

return module

Server Script

local SS = game:GetService("ServerScriptService")
local Enemy = script.Parent
local Base = require(SS:WaitForChild("Modules"):WaitForChild("EnemyBase"))
torpid shoalBOT
#

studio** You are now Level 4! **studio

torpid relic
#

Module script

local EnemyModule = {}

function EnemyModule.new(model)
  print(model.Humanoid)
end

return EnemyModule

Server script

local SS = game:GetService("ServerScriptService")
local enemyModel = script.Parent
local enemyModule = require(SS:WaitForChild("Modules"):WaitForChild("EnemyModule"))

local Enemy = enemyModule.new(enemyModel)
weak viper
#

ahh right right, that makes sense. thanks!!