Requiring (or calling) two module scripts at once with normal script

What i’m trying to do here is to call or require two module scripts at the same time when proximity triggered from ‘playerwhotriggered’, however i was only able to call one module script.
Side note both module scripts are located in two different locations:
One in serverstorage
And one in serversidedservice, i want to prioritize the first module script in serversidedservice then the one in serverstorage, is it by any means possible?

1 Like

I’m slightly confused what you’re trying to do, can you share some code?

ModuleScripts only run one time, ever, across all server scripts. When you require() them for the first time, they run top to bottom. Subsequent calls to require() (even in different scripts) don’t do anything except return the same exact object as the first time they ran.

2 Likes

I’m trying to require two modulescripts from proximity trigger, i was able to call the first but can’t do it with the second.
Here’s my script:

local ProximityPromptService = game:GetService("ProximityPromptService")
local changeteamscript = game:GetService("ServerStorage")
local Module = require(changeteamscript:WaitForChild("Modules"):WaitForChild("ChangeTeam"))

proximity.Triggered:Connect(function()
    Module()
    print(1)
        end)
1 Like

Sorry, I only see one module here—what do you mean by “can’t do it with the second”?

2 Likes

It returns a table error: attempt to call a table value - Server - Script:9
heres my updated script:

local proximity = script.Parent.ProximityPrompt
local ProximityPromptService = game:GetService("ProximityPromptService")
local modulescript2 = game:GetService("ServerScriptService")
local Module2 = require(modulescript2:WaitForChild("Modules"):WaitForChild("Engine"))
local modulescript1 = game:GetService("ServerStorage")
local Module = require(modulescript1:WaitForChild("Characters"):WaitForChild("Example1"))

proximity.Triggered:Connect(function(playerWhoTriggered)
	Module2()
	Module()
	print(1)
end)
1 Like

Engine must be returning a table, instead of a function like ChangeTeam does.

Did you write both these modules or are you just using them?

1 Like

just using them the examplecharacter one changes the player clothings, faces and other cosmetics features
the engine one handles team changing and other stuff like strings and other functions
The sceond modulescript (examplecharacter) works perfectly but not engine as its the one that is very important.

1 Like

You should ask whoever made the Engine module how they intend you to use it, then, or look inside of it to see if the creator left you any hints or examples.

1 Like

I don’t even think the Engine script itself is editable
image
due to this at the end

1 Like

Again, ask whoever made the script how to use it. It’s probably something like

local Engine = require(modulescript2:WaitForChild("Modules"):WaitForChild("Engine"))

proximity.Triggered:Connect(function(playerWhoTriggered)
	local eng = Engine.new()
	eng.SomeFunctionIDK()
end)

but I don’t know for sure because I didn’t write it. You could share the entire Engine script here, and we can try to reverse-engineer how to use it, or you can just ask whoever wrote it.

1 Like

i could give a snippet of it

local function defaultData():BaseData
	return {
		Zombiefied = false,
		ZombieType= "",
		IsImmune = false,
		AnimPlaying= false
	}
end

function Engine:Load(Player: Player)
	if Data[Player] then return end
	Data[Player] = defaultData()
end

function Engine:IsImmune(Player: Player): boolean
	if not Data[Player] then 
		Engine:Load(Player)
		return false
	end
	return Data[Player].IsImmune
end

function Engine:IsZombie(Player: Player): boolean
	if not Data[Player] then 
		Engine:Load(Player)
		return false
	end
	return Data[Player].Zombiefied
end
1 Like

Your code isn’t working because you’re trying to call the modulescript like its a local function. You have to specify which function to call like this:

local Engine = require(ReplicatedStorage.Engine)
Engine:Load(Players.Player1)
1 Like

Please edit your post to include the entire module script… but also please ask whoever wrote it. I don’t know which of these functions you’re supposed to call. Where did you get this module script from?

1 Like

From an open source game kit. The engine module script relies on parts with attributes that define the zombietype, my solution to this was to move the part with said attributes to the player, but that didn’t work.

1 Like

Your solution worked but it returns this error on the characterexample module
image
line of codes that cause this:

return function(Player)
	local Character = Player.Character
	if not Player:HasAppearanceLoaded() then
		while not Player:HasAppearanceLoaded() do
			task.wait()
		end
1 Like

For the characterexample module just require it like this:

local Module = require(ReplicatedStorage.Module)
Module(Players.Player1)
1 Like

Now it returns that Character is not a valid member of Players “Players” – once again triggered by the character modulescript, the current script i am using to require them both

local proximity = script.Parent.ProximityPrompt

local Players = game:GetService("Players")

local ProximityPromptService = game:GetService("ProximityPromptService")

local modulescript2 = game:GetService("ServerScriptService")

local Engine = require(modulescript2:WaitForChild("Modules"):WaitForChild("Engine"))

local character = game:GetService("ServerStorage")

local Module =require(character:WaitForChild("Characters"):WaitForChild("CharacterExample"))

proximity.Triggered:Connect(function()

Engine:Load(Players)

Module(Players)

print(1)

end)
1 Like

Of course it won’t work lol. I just put a random argument for the module, you’re supposed to script that in yourself.

1 Like

place a module inside a spawn function and the other one outside of it.

spawn (function()
   module1()
end)

module2()

this is just an example

1 Like