ok so i have 2 separate datastore scripts in sss and the maxhealth datastore is printing player had data twice and the speed prints gave player data twice while i have 3 other datastores that are the same script as these just edited but they print and function just fine while maxhealth is not saving and speed is
maxhealth script
local Data = game:GetService("DataStoreService"):GetDataStore("MaxHealth")
game.Players.PlayerAdded:Connect(function(plr)
local MaxHealth = Instance.new("Folder")
MaxHealth.Name = "MaxHealth"
MaxHealth.Parent = plr
local First = Instance.new("BoolValue")
First.Name = "First"
First.Parent = MaxHealth
local Second = Instance.new("BoolValue")
Second.Name = "Second"
Second.Parent = MaxHealth
local Third = Instance.new("BoolValue")
Third.Name = "Third"
Third.Parent = MaxHealth
local Fourth = Instance.new("BoolValue")
Fourth.Name = "Fourth"
Fourth.Parent = MaxHealth
local Fifth = Instance.new("BoolValue")
Fifth.Name = "Fifth"
Fifth.Parent = MaxHealth
print("Gave "..plr.Name.." MaxHealth Data")
local SavedItems = Data:GetAsync(plr.UserId)
if SavedItems then
First.Value = SavedItems.First or false
Second.Value = SavedItems.Second or false
Third.Value = SavedItems.Third or false
Fourth.Value = SavedItems.Fourth or false
Fifth.Value = SavedItems.Fifth or false
print(plr.Name.." had MaxHealth data")
else
First.Value = false
Second.Value = false
Third.Value = false
Fourth.Value = false
Fifth.Value = false
print(plr.Name.." didn't have MaxHealth data")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Saving = {
["First"] = (plr.MaxHealth).First.Value;
["Second"] = (plr.MaxHealth).Second.Value;
["Third"] = (plr.MaxHealth).Third.Value;
["Fourth"] = (plr.MaxHealth).Fourth.Value;
["Fifth"] = (plr.MaxHealth).Fourth.Value;}
Data:SetAsync(plr.UserId, Saving)
print("Saved "..plr.Name.."'s MaxHealth Data")
end)
speed script
local Data = game:GetService("DataStoreService"):GetDataStore("Speed")
game.Players.PlayerAdded:Connect(function(plr)
local Speed = Instance.new("Folder")
Speed.Name = "Speed"
Speed.Parent = plr
local Five = Instance.new("BoolValue")
Five.Name = "Five"
Five.Parent = Speed
local Ten = Instance.new("BoolValue")
Ten.Name = "Ten"
Ten.Parent = Speed
local Fifteen = Instance.new("BoolValue")
Fifteen.Name = "Fifteen"
Fifteen.Parent = Speed
local Twenty = Instance.new("BoolValue")
Twenty.Name = "Twenty"
Twenty.Parent = Speed
print("Gave "..plr.Name.." Speed Data")
local SavedItems = Data:GetAsync(plr.UserId)
if SavedItems then
Five.Value = SavedItems.Five or false
Ten.Value = SavedItems.Ten or false
Fifteen.Value = SavedItems.Fifteen or false
Twenty.Value = SavedItems.Twenty or false
print(plr.Name.." had Speed data")
else
Five.Value = false
Ten.Value = false
Fifteen.Value = false
Twenty.Value = false
print(plr.Name.." didn't have Speed data")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Saving = {
["Five"] = (plr.Speed).Five.Value;
["Ten"] = (plr.Speed).Ten.Value;
["Fifteen"] = (plr.Speed).Fifteen.Value;
["Twenty"] = (plr.Speed).Twenty.Value;}
Data:SetAsync(plr.UserId, Saving)
print("Saved "..plr.Name.."'s Speed Data")
end)

6 comments
oh alright thank you very much i tried implementing datastore 2 into my game before from alvinblox's video but it didnt work
but while having it all in one script if i wipe a certain set from the datastore2 like maxhealth because say of some exploiter problem how would i go about that?
You should secure your code for it not to be exploitable.
alright and one more thing the maxhealth is still not saving even with datastore2 but the speed is
the way i have it set up is when a player clicks a textbutton it fires a remote event and then the server takes away a set value from their experience data and sets their value to true on the maxhealth
That means the value is not changing if it doesn't save.