Can't reset DataStore and Data carries across scripts

Hello! Today I was trying to use this DataStore for my Tools the problem I am having is I can’t reset the Data for tools when I am testing the game. I have tried Re Writing the code a bunch of different ways AND I have looked at a bunch of tutorials and other forums but I can’t seem to get it to work the way I would like, I have tried adding a Table and separate Data for it listing all the tools in the folder but it just won’t work and it keeps saving the Data even if I delete the script. If anyone could help me out I would really appreciate it Thank You!

The script I have now

local name = "PurchasedSwords"
game.Players.PlayerAdded:connect(function(player)
local DataStore = game:GetService("DataStoreService")

local Starter = Instance.new("Folder",player)
Starter.Name = name

for i,v in pairs(game.ServerStorage.Swords:GetChildren()) do

	local Main = DataStore:GetDataStore(name .." ".. v.SwordName.Value.."Noob")
	local Backup = DataStore:GetDataStore(name .." ".. v.SwordName.Value.."Noob1")
	local x = Instance.new("BoolValue",Starter)
	x.Name = v.SwordName.Value 
	if Main:GetAsync(player.UserId) == Main:GetAsync(player.UserId) then

		x.Value = Main:GetAsync(player.UserId) or v.DefaultValue.Value
	else
		x.Value = Main:GetAsync(player.UserId) or v.DefaultValue.Value	
	end
end
end)

game.Players.PlayerRemoving:Connect(function(player)
for i,v in pairs(game.ServerStorage.Swords:GetChildren()) do 
	print("Getting")
	local DataStore = game:GetService("DataStoreService")
	local Main = DataStore:GetDataStore(name .." ".. v.SwordName.Value.."Noob")
	local Backup = DataStore:GetDataStore(name .." ".. v.SwordName.Value.."Noob1")
	Main:SetAsync(player.UserId, player[name][v.SwordName.Value].Value)
	Backup:SetAsync(player.UserId, player[name][v.SwordName.Value].Value)
	print("Saved")
end
end)

I dont fully understand your question. The data has already been saved. Disabling the code that calls SetAsync doesn’t delete the data from your datastore.

Usually you have something like

local DataStoreService = game:GetService(“DataStoreService”)

local playerData = DataStoreService:GetDataStore(“playerData”)

and you could just change the “playerData” to erase everything but in my case you can’t so I am trying to figure out how to erase the data of the unlocked tools so they are locked again

I have also tried something like that but it didn’t work

That just changes the datastore to point to a new datastore. The old one still exists at the old name. You’re naming datastores based on the current sword value. You should use constant datastore names and dynamically change the key used to access it instead of dynamically changing the datastore name.

Do you have an example I can reference from? I kind of understand what you mean

The api for that method goes into more details. DataStoreService | Roblox Creator Documentation

You shouldn’t be calling GetAsync over and over like that as well. Its throttled. Limits can be found here

1 Like

Alright thank you! ill look into it more