Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

wiki has a good article on arguments and parameters https://www.robloxdev.com/articles/Arguments-and-Parameters

1 answer

✓ Accepted answer

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.

4 comments

0

Basically you're saying to do Folder.Parent = Object?

0

Thanks, it works.

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.

0

This is already pointed out in the thread I linked.

This discussion is preserved as it was. New answers, comments, and votes are closed.