When making weapons, I gotten this idea of creating a module script which contains all of the functions of weapons inside it (For example, if I’m making a throwable bomb item, I would make the module script contain a function called “ThrowBomb”) and fire the function on a separate script.
Wouldn’t this be a smart move considering I’m adding different types of swords, bazooka’s, stuff like that or wouldn’t that cause issues?
No, what I meant is that the question you are asking is related to the Module Script. Therefore, I’m asking if I could take a look at the Module Script.
The notation “:” is used to create a method, useful for simulating OOP with Lua. You have two choices for calling a method. You can use the notation “:” or the notation “.”. The main difference is that with :, you don’t need to send the called table in first argument.
local WeaponsModules = {
Debounce = false
}
function WeaponsModules:ThrowBomb(...)
print(self.Debounce) -- false
end
WeaponsModules:ThrowBomb(...)
But with the notation “.” you need to send the called table in first argument.
function WeaponsModules:ThrowBomb(...)
print(self.Debounce) -- false
end
WeaponsModules.ThrowBomb(WeaponsModules, ...)
This can make it easier to use something like pcall.
local success, err = pcall(WeaponsModules.ThrowBomb, WeaponsModules, ...))
If you’re interested about OOP you can click here to read an article about roblox OOP.