Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To Creating Values To Save & Load Individually?

I'm creating a game where the player can chose from a range of abilities to unlock in any order they choose as long as they reach the requirements. Each ability can be levelled up the more it's used.

Right now I've just been creating, loading & savings all those values when the player joins, setting them to "0" if they're locked but is it possible for me to create the value when the player actually unlocks the ability and save it. So the player is only saving and loading what they've actually unlocked thus far.

For example

  • Player
    • Abilities

Player unlocks the Fireball ability so it becomes

  • Player
    • Abilities
      • Fireball

Everything inside "Abilities" is saved

1 answer

This looks like it's mostly a design question, so I'll try my best to give some basic ideas.

Personally, if you want the fireball's power to be determined by how experienced the player is with magic, I'd design it more like this:

  • Player (player object, obviously)
    • Magic (a stat that gets saved)
      • Fireball (not a stat, unlocked automatically, damage increases as "Magic" increases)
      • Thunder (not a stat, unlocked when "Magic" reaches level x)

etc. With this layout, only "Magic" needs to be saved and loaded, and the rest is handled based on its value.

But if you want each ability to have its own skill level (i.e. the more the player uses "Fireball", the better they get at it), then "Fireball" can be its own stat. I can see that being useful for if you want "Fireball" to be succeeded by another "Fire" attack, but if that's what you have in mind, you could do it like this:

  • Player
    • Magic (stat)
      • Fire (stat, player starts with "Fireball", when Fire reaches level 10 they unlock Volcano or whatever)

If you're confused by how you would code something like that, the wiki page walks you through how to get the basic setup done. https://developer.roblox.com/en-us/articles/Data-store

Try making a basic datastore that sets and gets a number value for "Magic" (or whatever you choose to name your ability level). When the player levels up, overwrite/save/set it. When the player joins the game, load/check/get it.

If you successfully get the "Magic" value, then you can choose what to do with it.

This is just pseudocode, but it should help you get some ideas:

-- Giving the player the ability
magicLevel = magicData:GetAsync(userid);
if magicLevel > 5 then
	-- let them cast Fireball
end
-- Making the ability more powerful
magicLevel = magicData:GetAsync(userid);
local baseDamage = 5; -- basic fire attack, does a little damage
local damage = (baseDamage * magicLevel); -- make it stronger when the player gets stronger
enemy.Health = enemy.Health - damage; -- deal the damage

If this was helpful, please upvote the answer or mark it as the solution, but if you have more questions, leave a comment :)

This discussion is preserved as it was. New answers, comments, and votes are closed.