So, I made a Module script inside of a actual script(not local script.) I am trying to clone a folder with Values inside of it into an actual player through two different scripts. Module and Acutal Script?
Here's the code for the Module..
local Module = {} function Module.CreateFolder() local plr local Folder = Instance.new("Folder", plr) Folder.Name = "Folder" Instance.new("IntValue", Folder).Name = "Tokens" Instance.new("IntValue", Folder).Name = "Codes" Instance.new("StringValue", Folder).Name = "Trade" Instance.new("BoolValue", Folder).Name = "BetaTester" Instance.new("BoolValue", Folder).Name = "Exploiter" Instance.new("BoolValue", Folder).Name = "Loaded" Instance.new("BoolValue", Folder).Name = "Accept" Instance.new("BoolValue", Folder).Name = "AFK" end return Module
Here's the actual script..
local Folder = require(script.Folder) game.Players.PlayerAdded:Connect(function(plr) Folder.CreateFolder() end)
I thought this would work because of me thinking that I can make my code as neat as possible, but it didn't put the folder into the player.
Question: How can I still keep the module script and access the function "plr" without the script doing things that I didn't want it to do?
Just make the player instance a parameter to the function.
Module Script:
function Module.CreateFolder(plr) ... end
Script:
local Folder = require(script.Folder) game.Players.PlayerAdded:Connect(function(plr) Folder.CreateFolder(plr) end)
One other thing that I want to note out is that the parent parameter of Instance.new
is deprecated and should not be used. The proper order of action is to instantiate the folder, configure its properties and children, and then parent it. The same applies all the IntValues, BoolValues, and StringValues you add to the folder as well.