Race/Species system

If I wanted to make like a species race system like rogue lineage (you join the game for the first time and you’re automatically given a race), would I need to use tables and insert the player or something with the PlayerAdded event? And how would I save that the next time they join? I’m not asking for entire scripts here, I’m just lost on how I would go about this. I haven’t found anything on the devforum or online about something like this.

I assume each race has properties

races = {

   race1 = {pay = 0, spawn = spawns.race1},

}

Then maybe each player has something like this

playerInfo = {

    race = race1,

}

Then you could retrieve these from the Module they are in.

function module:GetRace(raceName)
   if races[raceName] then
        return races[raceName]
   else
        return false
   end
end

This is essentially textbook the use case of DataStores.

I wouldn’t use tables, I’d just use a string value that represents the users species/race and reference that every time something that requires a specific species/race is called upon.

I’d figure each race would have their own settings/configurations and unique properties though, would there another way to do this without tables?

It’s “possible”, though for handling their unique properties I’d use tables - my answer was in reference to OP saving the data (and their idea of inserting players into a table).

1 Like

what does module:GetRace mean? I’m confused on that part

It’d be in a modulescript.

Based on the argument given from another script (localscript or serverscript), it’d look through the races that are in the races table and return that race if it could find it

So in a server script, you could require this module and say

local Race1 = module:GetRace(“race1”)

So if I wanted to make a person a certain race, would I set them equal to that race, which includes all the properties and stuff for the race?

You’d probably want to set their race to a string such as

Race = “race1”

and then anytime you need to check what properties comes with that race you could do

module:GetRace(Player.Race) or something like that

Thank you. I think I got a better understanding of how I can go about this. I’m not gonna mark a solution yet because I still got questions, so I’m just going to work on it for now

1 Like

A quick suggestion: You could make your own “Player instance”, have its own set properties, and most especially: have its own race in a dictionary/table. What’s good about this is that you can also make custom methods for it and there are more possibilities with it rather than the regular Player instance of Roblox. This is done through Object-Oriented Programming, and there is a highly-detailed and well-written tutorial on how to get your way through it. Check it out here.

1 Like

It’s not necessarily it’s own “Player Instance” but more of a table “object” that is attached to the actual Player Instance. :slight_smile:

Oh, that’s what I call it haha. Because I made my own ‘Players’ service and instance learning from your OOP tutorial. Kind of useful since there are more possibilities.

Remember that we aren’t necessarily actually creating objects and such, but we are just using Object-Oriented principles with tables and metatables in Roblox Lua.