Wouldn't it be smart placing functions of weapons inside of a module script?

Hello there.

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?

Yes. It would be more optimized considering the amount of weapons you are going to make functionality of.

1 Like

Alrighty then.
Also, what is this “self” on a Bomb function. I didn’t added it.
Screenshot 2024-06-10 221332

It must be on the Module Script. Could I take a look at it?

Oh, I’m planning on using the functions on normal scripts (Server and Client) since the weapons are going to be good ol’ gears.

1 Like

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.

Oh uh, okay then? Keep in mind I recently just started it

local WeaponsModule = {}
--//Sword\\--
--N/A
--//Bomb\\--
function WeaponsModule:ThrowBomb(Bomb, ThrowForce)
	
end
return WeaponsModule

Oh, nevermind. Don’t worry about this. It’s just a thing that the Roblox compiler does.
image

Alright. I’ve also managed to remove it by apparently just doing .ThrowBomb() instead of :ThrowBomb()

Thanks though!

1 Like

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.