Data Store Help

For the past 3 hours I’ve been trying to think up ways i could have this script assign a random race and save it but, every time i go into the game it doesn’t save and chooses a different race. How would i go about fixing this.

Also i am using data store 2

image

1 Like

I think DataStore2:Get doesn’t actually set the data if it doesn’t exist, based on the post?

It says Get returns the defaultValue passed in if it receives nil, but it never explicitly says Get calls Set. Could this be the reason? I mean that would be a major quality-of-life change they are missing out on, but yeah.
If so, you could set the value whenever RaceName changes, or just put Set somewhere else in your code:

RaceName.Changed:Connect(function(newValue)
	RaceDataStore:Set(newValue)
end)

-- or put this somewhere, lol

RaceDataStore:Set(RaceDataStore:Get(NewStand))

Relevant gotchas:

3 Likes

use the update function

haven’t used DataStore2 yet but maybe something like this

RaceDataStore:Update(function(race)
  if not race then
    return chooseRandomItem()
  end
end)

Edit: Or maybe this:

RaceDataStore:Set( RaceDataStore:Get( chooseRandomItem() ))
1 Like