generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I run a module?

Previous Thread :: Next Thread 
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 07:12 AM
This may seem basic, but I never learned how, can anyone tell me?
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
01 Jul 2015 07:26 AM
m = require(module)

m()
Report Abuse
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 07:51 AM
Hm, I ran that script, and for some reason I'm getting this in output.

05:50:44.464 - Players.Player.PlayerGui.DropStuff:8: attempt to call global 'drop_all_items' (a nil value)
05:50:44.464 - Stack Begin
05:50:44.465 - Script 'Players.Player.PlayerGui.DropStuff', Line 8
05:50:44.465 - Stack End
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
01 Jul 2015 07:51 AM
Post the script....
Report Abuse
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 07:55 AM
Heh, I fixed it, good enough for a newbie.

local Player = game.Players.LocalPlayer
local PlayerStats = ReplicatedStorage.PlayerStats["Data_"..game.Players.LocalPlayer.Name]

drop_all_items = require(Common_Function_Modules.DropAllItems)(Player, PlayerStats)

drop_all_items()
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
01 Jul 2015 07:55 AM
The code within the Module script, before you get confused.
Report Abuse
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 07:58 AM
@power

I fixed it already, I just added (Player, PlayerStats) since that was what the Module was trying to fetch from the LocalScript.

:P
Report Abuse
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 08:00 AM
Nevermind, I just tested it and now it's just nil again.


Here's the script:


local ReplicatedStorage = Game:GetService("ReplicatedStorage")
local Module_Engine = ReplicatedStorage:WaitForChild("Module_Engine")
local Common_Function_Modules = Module_Engine:WaitForChild("Common_Function_Modules")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local PlayerStats = ReplicatedStorage.PlayerStats["Data_"..game.Players.LocalPlayer.Name]

local drop_all_items = require(Common_Function_Modules.DropAllItems)(Player, PlayerStats)

while wait(0) do
if Char.Humanoid.Health == 0 then
drop_all_items()
end
end
Report Abuse
GraphicsSettings is not online. GraphicsSettings
Joined: 12 Sep 2013
Total Posts: 2883
01 Jul 2015 08:07 AM
?

b1
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
01 Jul 2015 08:19 AM
local func = require(Common_Function_Modules.DropAllItems) > Returns the contents from the module, right now a func

func(arg) -- call the func
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
01 Jul 2015 08:19 AM
Module scripts are made to be objects like you see in workspace, libraries, or service-like tools.

Check out what OOS (object oriented scripting) is.

http://wiki.roblox.com/index.php?title=OOP

You should be using a type of format, depending on what you are making, like this.

local module = {}

module.new = function(parameter)
local this = {
Example = parameter;
}

this.SetExample = function(self, a)
self.Example = a
end

return this
end

return module

---

local module = require(script.ModuleScript)

local a = module.new("Test")
print(a.Example) --> Test
a:SetExample("Asd") -- or you could do a.SetExample(a, "Asd")
print(a.Example) --> Asd
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
01 Jul 2015 08:20 AM
The reason why it says it's nil, is because you set the variable not to the function, but to the function AFTER it ran; so if it returns nothing it's nil.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image