[SOLVED] Datastores Error

So I have posted this before but I kept getting told to use tables and I did but this still isn’t working
and I’m not sure how to make this work.

local DataStoreService = game:GetService("DataStoreService")
local Endings = DataStoreService:GetDataStore("Endings")



game.Players.PlayerAdded:Connect(function(plr)
	local data
	local repStorage = game:GetService("ReplicatedStorage")
	
	
	
	local Completions = Instance.new("Folder")
	Completions.Name = "Completions"
	Completions.Parent = plr
	
	local E1V = Instance.new("BoolValue")
	E1V.Name = "E1Complete"
	E1V.Parent = Completions
	
	local E2V = Instance.new("BoolValue")
	E2V.Name = "E2Complete"
	E2V.Parent = Completions
	
	local E3V = Instance.new("BoolValue")
	E3V.Name = "E3Complete"
	E3V.Parent = Completions
	
	local E4V = Instance.new("BoolValue")
	E4V.Name = "E4Complete"
	E4V.Parent = Completions
	
	
	
	
	local success, errormessage = pcall(function()
		data = Endings:GetAsync(plr.UserId.."-Endings")
	end)
	
	
	if success then
		plr.Completions.E1Complete.Value = data[1]
		plr.Completions.E2Complete.Value = data[2]
		plr.Completions.E3Complete.Value = data[3]
		plr.Completions.E4Complete.Value = data[4]
		print("Data Successfully Loaded")
		
		
	else
		print("An Error Occured Loading Data: ".. errormessage)
	end
	
	

	
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local data = {}
	
	table.insert(data, plr.Completions.E1Complete.Value)
	table.insert(data, plr.Completions.E2Complete.Value)
	table.insert(data, plr.Completions.E3Complete.Value)
	table.insert(data, plr.Completions.E4Complete.Value)
	
	local repStorage = game:GetService("ReplicatedStorage")
	
	local success, errormessage = pcall(function()
		Endings:SetAsync(plr.UserId.."-Endings", data)
	end)
	
	if success then
		print("Data Saved Successfully")
		
	else
		print("Error loading data, Error Message: "..errormessage)
	end
	
	
	
	
	
end)

1 Like

You need to specify data and inform the script about whether data has been recorded and registered in the Endings datastore. If data returns nil, the script should default the values.

if success then
    if data then
	    plr.Completions.E1Complete.Value = data[1]
	    plr.Completions.E2Complete.Value = data[2]
	    plr.Completions.E3Complete.Value = data[3]
	    plr.Completions.E4Complete.Value = data[4]
	    print("Data Successfully Loaded")
    else
        print("The player" .. plr.Name .. "has not been registered yet.")
    end	
else
	print("An Error Occured Loading Data: ".. errormessage)
end

If it doesn’t work, please tell us what kind of error getting printed.

Nothing is happening and there is no errors

I don’t see any other programmatical errors that might happen except for the above. If there is no error, the only thing I recommend checking is

  • the Disabled property
  • Whether it is server-side
  • Script-executing areas like ServerScriptService service.

This works as I figured it out all of the values were client-sided not server-side tysm

1 Like