Access functions from other scripts?

Hi! I had a question on how to access functions from other scripts.

Can anyone tell me how to access functions from other scripts? Because, I want to make a door that can be opened. But, when the game ends, the door resets. However, the door’s script and the game end script are different scripts.

Thanks!
-coolguyweir

1 Like

have you looked into module scripts?

you can access functions from the module using a server script or local script

module scripts can even access other module scripts

4 Likes

for this you would have to use module scripts.

A module script is basically a utility script. to start working with a module script, you need to do require(ModuleScript). each module script has to return something, and whatever they return is what you can use to access stuff about what it holds.

for instance:
say you have a module named 'Door`, and inside of it you have the following code

local Door = {};
function Door.Open()
 print("opening door")
end

function Door.Close()
 print("Closing door");
end

return Door

Now you can do the following from a different script:

local Door = game.Service.etc.Door;
local door = require(Door);

door.Open();
door.Close();

note this: a module script can return any value except i believe nil.

here is an alvinblox video if you need more help

3 Likes