#Help with modules

1 messages · Page 1 of 1 (latest)

vivid hawk
#

I have no idea on how to use module scripts yet. Im making one where it prints a word then follows up wtih the players name, but it prints out "nil". How do I fix this?

local module = {
    easy = function(player)
        print("Easy")
        print(player)
    end,
}

return module```
#

also the server script

local plr
game.Players.PlayerAdded:Connect(function(player)
    plr = player
end)

local modulescript = require(game.ReplicatedStorage.ModuleScript)

modulescript.easy()```
mellow creek
#

pass plr var into function

vivid hawk
mellow creek
#

that is simplified

vivid hawk
gleaming orbit
mellow creek
#

demote him

vivid hawk
mellow creek
vivid hawk
mellow creek
#

where did you pass the var

vivid hawk
#

modulescript.easy(plr)

#

!!!

gleaming orbit
gleaming orbit
#

wait actually

#

that isnt the problem

#

it allows for them

#

it's just the piece of code you're running to fire the function is running before the player joins lol

mellow creek
#

dude you want to run the code in play mode not in test mode

mellow creek
#

or jsut put that function into playeradded

#

instead of plr var pass the player variable straight in

vivid hawk
#

okay i got it

gleaming orbit
mellow creek
#

i just woke up im getting dumb

gleaming orbit
vivid hawk
#

k thanks guys

#

👍

twilit kayak
#

but theres many ways to use a module

#

🤷‍♂️

old nymph
#

thats how you use modules ^^^

#

but at first I also had problems to understand modulescripts

#

cuz I didnt know for what reason I could need them

#

after I discovered "OOP" I slowly understood the usage of modulescripts

patent dust
#

once you get to a level of understand oop and module scripts your life just gets easier

old nymph
#

I would highly recommend going into roblox forums to understand

#

https://devforum.roblox.com/t/roblox-oop-object-oriented-programming/1639499/8
this is where I learned OOP (Object Orientated Programming). After seeing this I started using Modules and I basically improved so much than before

hasty mulchBOT
#

studio** You are now Level 16! **studio