Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help accessing player from module script and a actual script?

Asked by
B_rnz 171
5 years ago
Edited 5 years ago

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?

0
wiki has a good article on arguments and parameters https://www.robloxdev.com/articles/Arguments-and-Parameters User#22604 1 — 5y

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Basically you're saying to do Folder.Parent = Object? B_rnz 171 — 5y
0
Thanks, it works. B_rnz 171 — 5y
0
The issue isn't using the parent parameter, the issue is parenting it and then setting values. If you parent it immediately after creating it, you have the same issue. User#22604 1 — 5y
0
This is already pointed out in the thread I linked. RayCurse 1518 — 5y
Ad

Answer this question