|
| 27 Nov 2017 06:51 PM |
PlayerData = {}
game.Players.PlayerAdded:Connect(function(Player) --- table.insert(PlayerData, Player.UserId) PlayerData[Player.UserId] = {Cash = 400} --- end)
This is a script that basically assigns each player a cash value with a data table. Any possible ways to get the data of said user from another script? |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 27 Nov 2017 06:54 PM |
| could use _G or module script in this case i guess |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2017 06:58 PM |
'could use _G or module script in this case i guess'
I feel like _G is hacky.
How would I use ModuleScripts? |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 27 Nov 2017 07:00 PM |
Bindable Events/Functions
Fish Are Friends, Not Food |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 27 Nov 2017 07:02 PM |
| _G has it's pros and cons but using something like bindables for this would be hacky |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2017 07:04 PM |
| Give me some pointer on how to use ModuleScripts with this, they seem efficient for this purpose |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 27 Nov 2017 07:06 PM |
| could make a mini api for this thing i guess like: local api = {} api.Data = {} function #################### ############# = val end function api.GetData(key) return api.Data[key] or default i guess xd end return api maybe idk |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
| |
|
|
| 27 Nov 2017 07:24 PM |
A module script returns a value.
What can that value be? Anything.
You get the returned data in the module by doing: local data = require(ModuleScipt)--Data becomes the returned value |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 27 Nov 2017 07:28 PM |
| @Lae I'd say _G has the major downside of no ability to limit access (as far as I'm aware at least) where bindables can use getters and setters to limit direct access to the values held |
|
|
| Report Abuse |
|
|