Alright so, I am trying to make something in Roblox. It’s an FPS framework and it might become a game once my code is officially stable and ready for game use. Now the the gun itself is working fine including the FPS arms itself.
The tool itself contains the following:
- The weapon itself
- The code that will handle everything including FPS arms.
First of all I have the code require two module scripts.
First is the ModuleScript for the Configurations of the weapon. That will include animations for the FPS arms. Second is another module that is the system for the weapon itself. Handling every mechanics for the gun.
The modules get required when I already set the parent of the Tool in StarterPack. But when I set it to ReplicatedStorage then clone it to the player’s backpack it just won’t require it.
You can watch the video of the problem here: https://streamable.com/n7rj8b
Basically this is what it looks like in the explorer:
The screenshot when I just place the Tool in StarterPack:
Now I parent it somewhere else like ReplicatedStorage:
So what happens is I need it to work when a code clones the Tool into the players backpack but it won’t work. Resulting the code into not requiring the System module aforementioned earlier.
It does require one module which is the Config one but it doesn’t require the second module which is the system for all the gun mechanics and stuff.
So I have a clickable part to make a copy of the Tool and parent it to my Backpack. The code:
script.Parent.MouseClick:Connect(function(player)
local Tool = game.ReplicatedStorage.M4A1:Clone()
Tool.Parent = player.Backpack
end)
Looks pretty straightforward right? Now when you look at the part of the vid where I click the part. Yes it works, it does clone the tool then parent it to my Backpack. Now I equip the tool, it doesn’t even work. It doesn’t import the FPS arms and other stuff because it’s due to the fact that the code hasn’t even required the second module yet. In order for everything to work, the gun needs it’s two modules.
I checked the script in-game, it does exist there.
Ignore the name of the script btw. That’s just a name. Anyway, if you watched the whole video, you’ll see the tool is parented in StarterPack first, I equip the gun it works. Now I parent it to ReplicatedStorage, have the clickable part do the job. I equip the gun, doesn’t work anymore.
I even tried printing and the only module that is being required by the code is the Config. Here’s the screenshot:
You can see in the output, the Config module has been required by the localscript successfully while the system module is not required.
This is how I require the modules:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GunModules = ReplicatedStorage:WaitForChild("GunModules")
local Config = require(GunModules.Settings.M4A1)
local System = require(GunModules.System.M4A1)
Looks fine right? It looks like I typed it correctly. But I don’t get it why it doesn’t require the second module script.
For further suggestions and questions regarding this, reply below.
You can contact me through Discord: Duckrollerist#8679