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

Structure for sorting game assets (?)

Asked by
Trewier 146
6 years ago
Edited 6 years ago

I had previously asked this question on roblox forums and could not find any information so I direct my question to all you fellow developers out there, after spending roughly a year programming as a hobby I have come to the conclusion that I need better structure for how I layout my games. If anyone can direct me to some material with information as to different ways other developers have taken an approach to this. To be clear, I am not talking about DataStore, I am well aware how to use that.

A better example of how to show this is how I set up my own game structure keeping in mind that these are all folders containing different objects in each of them:

Workspace
    >Core
        >gameScripts
            >Script1
            >Script2
        >gameAssets
            >gunModel
        >remoteFunctions
            >remoteFunction1
        >playerData
            >Trewier
                >Value1
                >Value2

I'm not sure if there is a more efficient way as to how this all should be done, or if this should work as well as anything else out there. Any and all help is appreciated, thank you for your time.

-Trewier

1 answer

Log in to vote
1
Answered by 6 years ago

Using folders is good. Some other possibilities compared to putting everything in the workspace:

  • Use ModuleScripts to store any player data (strings, tables, custom classes, etc). All player data can be stored in ModuleScripts (example below). Technically you can store things like an unparented IntValue if you like.
  • Use ReplicatedStorage for all ModuleScripts and assets that will be needed by the client (and potentially the server). (You can move assets back into the workspace to work on them and then put them back where they belong when you're done.)
  • Use ServerStorage for assets only needed by the server
  • Use ServerScriptService for Scripts and ModuleScripts needed only by the server.

In each of those services I put more folders to group related things (like "Scripts").

Example of ModuleScripts storing how much money someone has:

local module = {}
local playerMoney = {}
function InitializePlayerMoney(player) -- Initialize/load money
    playerMoney[player] = 0
end
game.Players.PlayerAdded:Connect(InitializePlayerMoney)
for _, player in ipairs(game.Players:GetPlayers()) do
    InitializePlayerMoney(player)
end
function module.GetPlayerMoney(player)
    return playerMoney[player]
end
function module.SetPlayerMoney(player, money)
    playerMoney[player] = money
end
game.Players.PlayerRemoving:Connect(function(player) -- Release memory; could also save money to datastore
    playerMoney[player] = nil
end
return module

Do note that since this module

Instead of saving a single number (money), you can modify this to save a dictionary of values, like playerData[player] = {Stats = {}, Money = 0, XP = 100}. Then all your server scripts can access this information simply be requiring the ModuleScript -- the ModuleScript only initializes once and all the server scripts will share the data. (Clients will still need RemoteEvents/Functions to ask the server for this information, of course.)

0
Great job explaining everything, this certainly will end up helping me organize my projects more efficiently. Trewier 146 — 6y
Ad

Answer this question