I’m trying to make a normal datastore but there is a few problems right now. I’ll list them
#1: When 1 data changes the other one get the same amount of the one that changed.
#2: My datastore editor isn’t really working correctly with it. It shows different ones with the wrong key.
So I’m not really familiar with normal datastores because I’ve been mainly focused on datastore2 but some help would be really nice thx.
Script:
local ds = game:GetService("DataStoreService")
local BannedDataStore = ds:GetDataStore("BannedDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local ban1 = Instance.new("BoolValue", leaderstats)
ban1.Name = "ban1"
local ban2 = Instance.new("BoolValue", leaderstats)
ban2.Name = "ban2"
local bandata
local bandata2
local success, errormessage = pcall(function()
bandata = BannedDataStore:GetAsync(player.UserId.."bancheck")
bandata2 = BannedDataStore:GetAsync(player.UserId.."bancheck")
if bandata ~= nil then
ban1.Value = bandata
end
if bandata2 ~= nil then
ban2.Value = bandata2
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
BannedDataStore:SetAsync(player.UserId.."bancheck", player.leaderstats.ban1.Value) -- Save
BannedDataStore:SetAsync(player.UserId.."bancheck", player.leaderstats.ban2.Value) -- Save
end)
if success then
print("Data has been saved")
else
print("error when saving data")
warn(errormessage)
end
end)
The key is where the value gets stored.
GetAsync and SetAsync work a lot like some sort of cross-server table
if you did
tbl["foo"] = 4
tbl["foo"] = 3
“foo” of tbl will be overridden.
The same thing happens here.
Also, you should store your information in tables.
Try saving something like
bandata = {
Ban1 = ban1.Value,
Ban2 = ban2.Value
}
save(userid, bandata)
and if it exists in the save,
ban1.Value = save.Ban1
ban2.Value = save.Ban2
1 Like
Sorry I don’t really get it …
If I give you an empty text file and I tell you to make it say “hello,” then i tell you to make it say “goodbye” instead, you have just overridden the contents of the file. The same thing happens here when you try to save two things into the same exact place.
Oh okay so if its the same key it overrights?
Yes, that is the point. They key is an identifier, it represents where that data will be stored. And as I mentioned before, you do not need to store it in 2 different places, you can store it in one place as a table.
ahhhh I’m trying to think of how to put it in the script but I can’t think of it :v
You got the same number is because the key is the same
bandata = BannedDataStore:GetAsync(player.UserId.."bancheck")
bandata2 = BannedDataStore:GetAsync(player.UserId.."bancheck")
both keys for example will be "231231bancheck"
so u want to make the keys different
like this
bandata = BannedDataStore:GetAsync(player.UserId.."bancheck")
bandata2 = BannedDataStore:GetAsync(player.UserId.."bancheck2")
same with the setAsync
BannedDataStore:SetAsync(player.UserId.."bancheck", player.leaderstats.ban1.Value) -- Save
BannedDataStore:SetAsync(player.UserId.."bancheck2", player.leaderstats.ban2.Value) -- Save
2 Likes
yeah I had that at first but it still seem to not work right thats why I changed it,
The second ban wouldnt save
you are basically breaking it, try to put it back to what it was before
and look at the errors
maybe ur ban2.Value is nil or something
just do it and look at the errors
It wasn’t nil because in the game I used the console to change the value to true. The ban1 saved but the ban2 didn’t want to :< Ill retest it
yesh sir check deh errors
/sploiter 30chars
Okay so I retested it and it worked tysm!