I am trying to add LocalScripts into a ModuleScript so when I require it and I say "lightsaber", it clones the lightsaber script inside the module, into the players PlayerGui or Backpack..
I tried this and It didn't work, so I found all the children in my backpack and It wasn't there.. So it clearly isn't working correctly
Here is what I did so clone it into the players Backpack
local Module = {} if Message:lower() == "saber" then script.Injects.lightsaber:Clone().Parent = player.Backpack end return module
You're calling the module, but giving it no function to run, from what I can see. A simple fix would be just calling a function within the module. Below is an example modified from your code:
local module = {} module.CloneItem = function(msg,plr) -- This is creating a function in the table "module". local msg = msg:lower(msg) -- Setting the message to be lower case, as you did. if msg == "lightsaber" then -- If the message is "lightsaber" local item = script:WaitForChild("Injects"):FindFirstChild(msg) then -- Creating a reference to the script if item then -- Checking if the script exists item:Clone().Parent = plr:WairForChild("Backpack") -- Adding the script to the players backpack item.Disabled = false -- Disabling the script so it can run, you can remove this if need be. end end end return modules
Now, since you now have your module script created, you need to require it. This is assuming that you are using a server script to require and run the module.
local OnChatModule = require(--[[Put the module location here]]) game.Players.PlayerAdded:connect(function(p) -- When the player joins p.Chatted:connect(function(msg) -- When player chats OnChatModule.CloneItem(msg,plr) -- Finally, checking the module script if the message matches and running that code if it is. end) end)
Please note that I wrote this on mobile, so I'm unclear if it'll work or not.