Attempt to index boolean with value name?

the problem im having, im using datastore 2 but tweaked a little bit, but the loadup always messes up because its thinking its a boolean value when its a number value?

local Players = game:GetService("Players")
local DataStore2 = require(game.ReplicatedStorage.DataStore2) -- This is the Module we need I will post it in Description
local Settings = require(game.ReplicatedStorage:FindFirstChild("Settings"))

DataStore2.Combine("DoneTest","Cash","Bank","EyeColor","Hair","Shirt","Pants","Tattoo","HairColor","SkinColor","FirstName","LastName","Gender","Camo","PrisonTime","Arrested","Face","Fish Caught","CarColor","InteriorColor","InteriorWalls","ExteriorWalls","GunPermit","GymMembership","Slot1","Slot2","Slot3","Slot4")


game.ReplicatedStorage:FindFirstChild("Remotes"):FindFirstChild("ToDatastore").OnServerEvent:Connect(function(plr,gui)
	print("got first event")
	local gui = gui
	for i,v in pairs(Settings) do
		wait(0.1)
		local datastore = DataStore2(i,plr)
		local where = v.Where
		if v.Where ~= "Player" then
			if plr:findFirstChild(v.Where) then
				where = plr[v.Where]
			else
				local folder = Instance.new("Folder",plr)
				folder.Name = v.Where

				where = folder
			end
		end

		if v.Where == "Player" then
			where = plr
		end
		--// Creates the Value
		local val = Instance.new(v.What,where)
		val.Name = i
		val.Value = v.Value
        dotest(plr,val,gui)

		--// Loading
		if datastore:Get() ~= nil then ---- Line where messes up
				val.Value = datastore:Get()
			end
		
		

		--//Saving
		val.Changed:connect(function()
				datastore:Set(val.Value)
				print("saved players value")
		end)
		print("fart")

	end
end)
print("fart3")


function dotest(plr,val,gui)
	if val.Name == "DoneTest" then
		local typeofe = "StartIntro"
		gui.Event:FireClient(plr,typeofe)
		gui = nil
		print("sent 2nd event")
		else
	end
end

okay i’ve never worked with datastores, so i apologize if i’m not helping at all

but what exactly does datastore = DataStore2(i,plr) do?

there’s probably an issue in that line

1 Like

i figured it out, this specific system had a mainkey in the datastore combine i forgot to add, kinda a dumb mistake on my part but it is what it is

oh

is this a certified programmer moment?

1 Like

Okay quite alot of problems with this code (other than it being dirty lol)

First: Memory leak

Whenever this “ToDatastore” event is triggered a new event is connected to a function for no reason because you’ve put that event inside another event. This will keep taking up memory and will eventually lead to a memory leak on the server which will be pretty problematic because memory leaks on the server can last for days.

Second: Datastore2

Datastore2 used to be a great module (atleast I heard) but alot of the features that it offered have now been added by roblox themselves and the module is quite old now.

Also datastore2’s automatic nature of retrying alot when one request fails can cause more harm than good.

I recommend either just using regular datastoreservice (which I use) or profileservice which is a newer module for datastoreservice that is still updated and used (I used to use).