Hello as I’ve been learning datastores I’ve been making a tower defense game and its been going great! but I’ve encountered an issue first hand and it is that when I add a new tower if a player has their data saved before the addition of a tower the person cannot buy this tower. I have tried various ways but did not find a way. Its like comparing two data tables
you use this to check if a tower is already bought or not, but that wont work if they dont have that tower, since its nil. You can instead just check if they have it in the table by doing
if Towers["testtower2"] == nil then --if they dont have the tower
Doing it with the Bought part
if Towers["testtower2"]["Bought"] == nil then
would return an error because “testtower2” == nil
You should remove the Bought info all together and instead check if the tower is nil inside the data table.
Then to add the tower you’d just do
--as an example, DataTowers is the datastore table, Tower is the tower you're trying to buy, so "testtower2"
--Towers is the buyable towers.
DataTowers[Tower] = Towers[Tower]
I solutioned this because this would work but the script I listed wasn’t the real script for the game but in my game there is a lot of towers and the issue is then checking if multiple towers are missing without having to manually make sure for every tower which makes the script messy
yes but I don’t know how to do this, I’ve already tried but it returns a random tower as missing when another tower was missing and the random tower isn’t missing.