This script saves the data

    local datastore2 = game:GetService("DataStoreService"):GetDataStore("Data2") 
    local repsto = game:GetService("ReplicatedStorage") 
    local RemoteEvent = repsto:WaitForChild("Save")
    
   local function Save (plr) 
    	print("CONNECTED") 
    	local Jumps = plr.leaderstats.Jumps 
    	datastore2:SetAsync(plr, Jumps.Value) 
    	print(datastore2:GetAsync(plr)) 
    	RemoteEvent:FireClient(plr) 
    end 
    RemoteEvent.OnServerEvent:Connect(Save)

This script loads the data

local datastore = game:GetService("DataStoreService"):GetDataStore("Data") 
local datastore2 = game:GetService("DataStoreService"):GetDataStore("Data2") 
local repsto = game:GetService("ReplicatedStorage") 
local RemoteEvent = repsto:WaitForChild("Unlock") 

local function SetupData (Player) 
    local plr = "user_" .. Player.userId 
    local plrdata = datastore:GetAsync(plr) 
    local plrdata2 = datastore2:GetAsync(plr)
    print("INITIATING") 
    print(datastore2:GetAsync(plr)) 
    if plrdata == true then 
	    RemoteEvent:FireClient(Player) 
	    Player.Team = game.Teams.End 
	    Player:LoadCharacter() 
	    RemoteEvent:FireClient(Player) 
    else 
	    datastore:SetAsync(plr, false) 
    end 
    --This is the part where you probably should read
	if plrdata2 ~= nil or 0 then 
	    Player.leaderstats.Jumps.Value = plrdata2
	    print("plrdata2isnil") 
	    print(datastore2:GetAsync(plr)) 
    else 
	    datastore2:SetAsync(plr, 0) 
	    print("plrdata2isnotnil") 
	    print(datastore2:GetAsync(plr)) 
    end 
    --This is the part where you probably should read
end 

game.Players.PlayerAdded:Connect(SetupData)

Using print(datastore2:GetAsync(plr)) i knew that it did save but when i join the game it doesn't, everything else works.

6 comments

0

if it helps, there is 2 datastore, the first one is "datastore" and then the other one is "datastore2", "datastore" stores a bool value and the "datastore2" stores a int value, and that the only problem here is that when i join it doesnt save, also i dont recieve any error

0

I dont get an error when I try it. It is most likely your game that is causing the issue.

2

if plrdata2 ~= nil or 0 then doesn't behave like you think it does. Really, it should be if plrdata2 ~= nil or plrdata2 ~= 0 then. Your if statement will always pass because 0 is truthy.

0

What are you attempting the test on? Try and do it in a normal Roblox game and ensure API services is switched on.

1

you don't need two separate data stores. Just save a table that includes both the bool and int value.

0

at this time i was new to data store and didn't really get how to use it, but now i do know. this question is answered