Datastore problems

My datastore worked 100% before but now it doesn’t work anymore. It gives many, many errors and warnings. Why this happens:

14:13:20.691 ServerScriptService.datastore:907: attempt to concatenate string with nil - Server - datastore:907

14:13:20.660 value of type nil cannot be converted to a number - Server - datastore:797
14:13:20.660 value of type nil cannot be converted to a number - Server - datastore:799
14:13:20.660 value of type nil cannot be converted to a number - Server - datastore:800
14:13:20.661 value of type nil cannot be converted to a number - Server - datastore:801
14:13:20.661 value of type nil cannot be converted to a number - Server - datastore:802
14:13:20.661 value of type nil cannot be converted to a number - Server - datastore:803
14:13:20.661 value of type nil cannot be converted to a number - Server - datastore:804
14:13:20.661 value of type nil cannot be converted to a number - Server - datastore:810
14:13:20.662 value of type nil cannot be converted to a number - Server - datastore:811
14:13:20.662 value of type nil cannot be converted to a number - Server - datastore:812
14:13:20.662 value of type nil cannot be converted to a number - Server - datastore:813
14:13:20.663 value of type nil cannot be converted to a number - Server - datastore:814
14:13:20.663 value of type nil cannot be converted to a number - Server - datastore:815
14:13:20.663 value of type nil cannot be converted to a number - Server - datastore:816
14:13:20.663 value of type nil cannot be converted to a number - Server - datastore:817
14:13:20.664 value of type nil cannot be converted to a number - Server - datastore:818
14:13:20.664 value of type nil cannot be converted to a number - Server - datastore:819
14:13:20.665 value of type nil cannot be converted to a number - Server - datastore:820
14:13:20.665 value of type nil cannot be converted to a number - Server - datastore:821
14:13:20.665 value of type nil cannot be converted to a number - Server - datastore:826
14:13:20.665 value of type nil cannot be converted to a number - Server - datastore:827
14:13:20.666 value of type nil cannot be converted to a number - Server - datastore:828
14:13:20.666 value of type nil cannot be converted to a number - Server - datastore:829
14:13:20.666 value of type nil cannot be converted to a number - Server - datastore:830
14:13:20.666 value of type nil cannot be converted to a number - Server - datastore:831
14:13:20.667 value of type nil cannot be converted to a number - Server - datastore:832
14:13:20.667 value of type nil cannot be converted to a number - Server - datastore:833
14:13:20.667 value of type nil cannot be converted to a number - Server - datastore:834
14:13:20.668 value of type nil cannot be converted to a number - Server - datastore:835
14:13:20.669 value of type nil cannot be converted to a number - Server - datastore:836
14:13:20.675 value of type nil cannot be converted to a number - Server - datastore:837
14:13:20.675 value of type nil cannot be converted to a number - Server - datastore:838
14:13:20.676 value of type nil cannot be converted to a number - Server - datastore:839
14:13:20.676 value of type nil cannot be converted to a number - Server - datastore:840
14:13:20.676 value of type nil cannot be converted to a number - Server - datastore:841
14:13:20.676 value of type nil cannot be converted to a number - Server - datastore:842
14:13:20.676 value of type nil cannot be converted to a number - Server - datastore:843
14:13:20.677 value of type nil cannot be converted to a number - Server - datastore:844
14:13:20.677 value of type nil cannot be converted to a number - Server - datastore:845
14:13:20.677 value of type nil cannot be converted to a number - Server - datastore:846
14:13:20.678 value of type nil cannot be converted to a number - Server - datastore:847
14:13:20.678 value of type nil cannot be converted to a number - Server - datastore:848
14:13:20.678 value of type nil cannot be converted to a number - Server - datastore:849
14:13:20.678 value of type nil cannot be converted to a number - Server - datastore:850

14:13:37.152 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.153 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.154 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.155 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.156 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.157 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.158 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.158 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.159 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.160 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.161 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.162 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:37.164 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“Rebirths”)’ - Studio
14:13:40.997 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“tasks”)’ - Studio
14:13:41.006 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“tasks”)’ - Studio
14:13:41.009 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“tasks”)’ - Studio
14:13:41.012 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“tasks”)’ - Studio
14:13:41.040 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“tasks”)’ - Studio
14:13:41.040

14:13:41.067 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“leaderstats”)’ - Studio
14:13:41.068 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“leaderstats”)’ - Studio
14:13:41.069 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“leaderstats”)’ - Studio
14:13:41.069 Infinite yield possible on ‘Players.FGJepperigamer:WaitForChild(“leaderstats”)’ - Studio





local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")

local database = DataStoreService:GetDataStore("MyDataStore")
local sessionData = {}



function PlayerAdded(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	print("plrrrr" .. player.UserId)
	
	local boksit = Instance.new("Folder")
	boksit.Name = "Boksit"
	

	
	local setting = Instance.new("Folder")
	setting.Name = "setting"
	
	local vspeed = Instance.new("IntValue", setting)
	vspeed.Name = "speed"
	
	local vshop = Instance.new("IntValue", setting)
	vshop.Name = "shop"
	
	local vinv = Instance.new("IntValue", setting)
	vinv.Name = "inventory"
	
	local vtask = Instance.new("IntValue", setting)
	vtask.Name = "task"
	
	local vtp = Instance.new("IntValue", setting)
	vtp.Name = "tp"
	
	local vlow = Instance.new("IntValue", setting)
	vlow.Name = "low"
	
	local vshadow = Instance.new("IntValue", setting)
	vshadow.Name = "shadow"
	
	local vstyle = Instance.new("IntValue", setting)
	vstyle.Name = "style"
	
	local vbrightness = Instance.new("IntValue", setting)
	vbrightness.Name = "brightness"
	
	local vmusic = Instance.new("IntValue", setting)
	vmusic.Name = "music"
	
	local venv = Instance.new("IntValue", setting)
	venv.Name = "environment"

	local vtrade = Instance.new("IntValue", setting)
	vtrade.Name = "trade"
	
	
	
	
	local stat = Instance.new("Folder")
	stat.Name = "stats"
	
	local sbutton = Instance.new("IntValue", stat)
	sbutton.Name = "sbutton"
	
	local scoin = Instance.new("IntValue", stat)
	scoin.Name = "scoin"
	
	local scrown = Instance.new("IntValue", stat)
	scrown.Name = "scrown"
	
	local sdaily = Instance.new("IntValue", stat)
	sdaily.Name = "sdaily"
	
	local sdailyopen = Instance.new("IntValue", stat)
	sdailyopen.Name = "sdailyopen"
	
	local sdeath = Instance.new("IntValue", stat)
	sdeath.Name = "sdeath"
	
	local seasy = Instance.new("IntValue", stat)
	seasy.Name = "seasy"
	
	local sepic = Instance.new("IntValue", stat)
	sepic.Name = "sepic"
	
	local slegendary = Instance.new("IntValue", stat)
	slegendary.Name = "slegendary"
	
	local smedium = Instance.new("IntValue", stat)
	smedium.Name = "smedium"
	
	local srare = Instance.new("IntValue", stat)
	srare.Name = "srare"
	
	local sexclusive = Instance.new("IntValue", stat)
	sexclusive.Name = "sexclusive"
	
	local sgem = Instance.new("IntValue", stat)
	sgem.Name = "sgem"
	
	local sgemspent = Instance.new("IntValue", stat)
	sgemspent.Name = "sgemspent"
	
	local shard = Instance.new("IntValue", stat)
	shard.Name = "shard"
	
	local simpossible = Instance.new("IntValue", stat)
	simpossible.Name = "simpossible"
	
	local sjoined1 = Instance.new("IntValue")
	sjoined1.Name = "sjoined1"
	
	local sjoined2 = Instance.new("IntValue")
	sjoined2.Name = "sjoined2"
	
	local sjoined3 = Instance.new("IntValue")
	sjoined3.Name = "sjoined3"
	
	local srebirth = Instance.new("IntValue", stat)
	srebirth.Name = "srebirth"
	
	local srobux = Instance.new("IntValue", stat)
	srobux.Name = "srobux"
	
	local stime = Instance.new("IntValue", stat)
	stime.Name = "stime"
	
	local stotaltask = Instance.new("IntValue", stat)
	stotaltask.Name = "stotaltask"
	
	local strade = Instance.new("IntValue", stat)
	strade.Name = "strade"
	
	local swin = Instance.new("IntValue", stat)
	swin.Name = "swin"
	
	

	
	


	
	local fff = Instance.new("Folder")
	fff.Name = "fff"
	local ttt = Instance.new("IntValue", fff)
	ttt.Name = "ttt"
	local ttt2 = Instance.new("IntValue", fff)
	ttt2.Name = "ttt2"
	local ttt3 = Instance.new("IntValue", fff)
	ttt3.Name = "ttt3"
	local passi = Instance.new("Folder")
	passi.Name = "passi"
	local tp = Instance.new("IntValue", passi)
	tp.Name = "tp"
	local gui = Instance.new("Folder")
	gui.Name = "guiof"
	local of = Instance.new("IntValue", gui)
	of.Name = "of"

	local tasks = Instance.new("Folder")
	tasks.Name = "tasks"
	local et1 = Instance.new("IntValue", tasks)
	et1.Name = "et1"
	local eraha = Instance.new("IntValue", tasks)
	eraha.Name = "eraha"
	local eraha2 = Instance.new("IntValue", tasks)
	eraha2.Name = "eraha2"
	local eraha3 = Instance.new("IntValue", tasks)
	eraha3.Name = "eraha3"
	local mraha = Instance.new("IntValue", tasks)
	mraha.Name = "mraha"
	local mraha2 = Instance.new("IntValue", tasks)
	mraha2.Name = "mraha2"
	local mraha3 = Instance.new("IntValue", tasks)
	mraha3.Name = "mraha3"
	local hraha = Instance.new("IntValue", tasks)
	hraha.Name = "hraha"
	local hraha2 = Instance.new("IntValue", tasks)
	hraha2.Name = "hraha2"
	local hraha3 = Instance.new("IntValue", tasks)
	hraha3.Name = "hraha3"
	local iraha = Instance.new("IntValue", tasks)
	iraha.Name = "iraha"
	local iraha2 = Instance.new("IntValue", tasks)
	iraha2.Name = "iraha2"
	local iraha3 = Instance.new("IntValue", tasks)
	iraha3.Name = "iraha3"
	local et2 = Instance.new("IntValue", tasks)
	et2.Name = "et2"
	local et3 = Instance.new("IntValue", tasks)
	et3.Name = "et3"
	
	local mt1 = Instance.new("IntValue", tasks)
	mt1.Name = "mt1"
	local mt2 = Instance.new("IntValue", tasks)
	mt2.Name = "mt2"
	local mt3 = Instance.new("IntValue", tasks)
	mt3.Name = "mt3"
	
	local ht1 = Instance.new("IntValue", tasks)
	ht1.Name = "ht1"
	local ht2 = Instance.new("IntValue", tasks)
	ht2.Name = "ht2"
	local ht3 = Instance.new("IntValue", tasks)
	ht3.Name = "ht3"
	
	local it1 = Instance.new("IntValue", tasks)
	it1.Name = "it1"
	local it2 = Instance.new("IntValue", tasks)
	it2.Name = "it2"
	local it3 = Instance.new("IntValue", tasks)
	it3.Name = "it3"
	
	local inv = Instance.new("Folder")
	inv.Name = "INV"
	local inv2 = Instance.new("IntValue", inv)
	inv2.Name = "INV2"
	local inv3 = Instance.new("IntValue", inv)
	inv3.Name = "INV3"
	
	local titlet = Instance.new("Folder")
	titlet.Name = "Titlet"
	local tt = Instance.new("IntValue", titlet)
	tt.Name = "tt"
	local tr1 = Instance.new("IntValue", titlet)
	tr1.Name = "r1"
	local tr2 = Instance.new("IntValue", titlet)
	tr2.Name = "r2"
	local tr3 = Instance.new("IntValue", titlet)
	tr3.Name = "r3"
	local tr4 = Instance.new("IntValue", titlet)
	tr4.Name = "r4"
	local ts1 = Instance.new("IntValue", titlet)
	ts1.Name = "s1"
	local ts2 = Instance.new("IntValue", titlet)
	ts2.Name = "s2"
	local te1 = Instance.new("IntValue", titlet)
	te1.Name = "e1"
	local te2 = Instance.new("IntValue", titlet)
	te2.Name = "e2"
	local tl1 = Instance.new("IntValue", titlet)
	tl1.Name = "l1"
	local tl2 = Instance.new("IntValue", titlet)
	tl2.Name = "l2"
	local tm = Instance.new("IntValue", titlet)
	tm.Name = "m"
	local tvip = Instance.new("IntValue", titlet)
	tvip.Name = "vip"
	
	local rebirthf = Instance.new("Folder")
	rebirthf.Name = "Rebirths"
	
	local lvl = Instance.new("Folder")
	lvl.Name = "uplvl"
	
	local rare = Instance.new("IntValue")
	rare.Name = "Rare"
	rare.Parent = boksit
	
	local load = Instance.new("Folder")
	load.Name = "Load"
	
	local loaded = Instance.new("IntValue")
	loaded.Name = "Loaded"
	loaded.Parent = load
	
	local epic = Instance.new("IntValue")
	epic.Name = "Epic"
	epic.Parent = boksit
	
	local rebirth = Instance.new("IntValue")
	rebirth.Name = "Rebirth"
	rebirth.Parent = rebirthf
	
	local rebirtht = Instance.new("IntValue")
	rebirtht.Name = "RebirthT"
	rebirtht.Parent = rebirthf
	
	local legendary = Instance.new("IntValue")
	legendary.Name = "Legendary"
	legendary.Parent = boksit
	
	local exclusive = Instance.new("IntValue")
	exclusive.Name = "Exclusive"
	exclusive.Parent = boksit
	
	local vipass = Instance.new("IntValue", boksit)
	vipass.Name = "vipass"
	
	local dailyb = Instance.new("IntValue")
	dailyb.Name = "Dailyb"
	dailyb.Parent = boksit
	
	local coinup = Instance.new("IntValue")
	coinup.Name = "coinup"
	coinup.Parent = lvl
	
	local speedup = Instance.new("IntValue")
	speedup.Name = "speedup"
	speedup.Parent = lvl
	
	local freekiulup = Instance.new("IntValue")
	freekiulup.Name = "freekiulup"
	freekiulup.Parent = lvl
	
	local luckyup = Instance.new("IntValue")
	luckyup.Name = "luckyup"
	luckyup.Parent = lvl
	
	local nohotup = Instance.new("IntValue")
	nohotup.Name = "nohotup"
	nohotup.Parent = lvl
	
	local palkintoja = Instance.new("Folder")
	palkintoja.Name = "Palkintoja"
	
	local pelipalkinto = Instance.new("IntValue")
	pelipalkinto.Name = "Pelipalkinto"
	pelipalkinto.Parent = palkintoja
	
	local pelipalkinto2 = Instance.new("IntValue")
	pelipalkinto2.Name = "PelipalkintoS"
	pelipalkinto2.Parent = palkintoja
	
	local pelipalkinto3 = Instance.new("IntValue")
	pelipalkinto3.Name = "PelipalkintoM"
	pelipalkinto3.Parent = palkintoja
	
	local pelipalkinto4 = Instance.new("IntValue")
	pelipalkinto4.Name = "PelipalkintoH"
	pelipalkinto4.Parent = palkintoja
	
	
	local Koodit = Instance.new("Folder")
	Koodit.Name = "Koodit"
	
	local k1 = Instance.new("IntValue")
	k1.Name = "K1"
	k1.Parent = Koodit
	
	local k2 = Instance.new("IntValue")
	k2.Name = "K2"
	k2.Parent = Koodit
	
	local k3 = Instance.new("IntValue")
	k3.Name = "K3"
	k3.Parent = Koodit
...
	
	local k55 = Instance.new("IntValue")
	k55.Name = "K55"
	k55.Parent = Koodit
	
	
	local saunat = Instance.new("Folder")
	saunat.Name = "Saunat"
	
	local alueet = Instance.new("Folder")
	alueet.Name = "Alueet"
	
	local ranta = Instance.new("IntValue")
	ranta.Name = "ranta"
	ranta.Parent = alueet
	
	local laava = Instance.new("IntValue")
	laava.Name = "laava"
	laava.Parent = alueet
	
	
	
	local sauna2 = Instance.new("IntValue")
	sauna2.Name = "sauna2"
	sauna2.Parent = saunat
	
	local sauna3 = Instance.new("IntValue")
	sauna3.Name = "sauna3"
	sauna3.Parent = saunat
	
	local sauna4 = Instance.new("IntValue")
	sauna4.Name = "sauna4"
	sauna4.Parent = saunat
	
	local sauna5 = Instance.new("IntValue")
	sauna5.Name = "sauna5"
	sauna5.Parent = saunat
	
	local sauna6 = Instance.new("IntValue")
	sauna6.Name = "sauna6"
	sauna6.Parent = saunat
	
	local sauna7 = Instance.new("IntValue")
	sauna7.Name = "sauna7"
	sauna7.Parent = saunat
	
	local sauna8 = Instance.new("IntValue")
	sauna8.Name = "sauna8"
	sauna8.Parent = saunat

	local sauna9 = Instance.new("IntValue")
	sauna9.Name = "sauna9"
	sauna9.Parent = saunat
	
	local sauna11 = Instance.new("IntValue")
	sauna11.Name = "sauna11"
	sauna11.Parent = saunat
	
	
	local saunapower = Instance.new("IntValue")
	saunapower.Name = "SaunaPower"
	saunapower.Parent = leaderstats
	
	local dollars = Instance.new("IntValue")
	dollars.Name = "Coins"
	dollars.Parent = leaderstats
	
	local gems = Instance.new("IntValue")
	gems.Name = "Gems"
	gems.Parent = leaderstats
	
	local crowns = Instance.new("IntValue")
	crowns.Name = "Crowns"
	crowns.Parent = leaderstats
	
	local success = nil
	local playerData = nil
	local attempt = 1

	repeat
		success, playerData = pcall(function()
			print("toimii")
			return database:GetAsync(player.UserId)
		end)


		attempt += 1
		if not success then
			warn(playerData)
			loaded.Value = 1
			task.wait(3)
		end
	until success or attempt == 5
	if success then
		print("Connected to database")
		if not playerData then
			print("Assigning default data")
			playerData = {
				["Dollars"] = 50,
				["Gems"] = 0,
				["Crown"] = 0,
				["Sauna2"] = 0,
				["Sauna3"] = 0,
				["Sauna4"] = 0,
				["Sauna5"] = 0,
				["Sauna6"] = 0,
				["Sauna7"] = 0,
				["Sauna8"] = 0,
				["Sauna9"] = 0,
				["Sauna11"] = 0,
				["Ranta"] = 0,
				["Laava"] = 0,
				["saunapower"] = 0,
				["s1"] = 0,
				["s2"] = 0,
				["s3"] = 0,
				["s4"] = 0,
				["s5"] = 0,
				["s6"] = 0,
				["s7"] = 0,
				["s8"] = 0,
				["s9"] = 0,
				["s10"] = 0,
				["s11"] = 0,
				["s12"] = 0,
				["s13"] = 0,
				["s14"] = 0,
				["s15"] = 0,
				["s16"] = 0,
				["s17"] = 0,
				["s18"] = 0,
				["s19"] = 0,
				["s20"] = 0,
				["s21"] = 0,
				["s22"] = 0,
				["s23"] = 0,
				["s24"] = 0,
				["s25"] = 0,
				["s26"] = 0,
				["s27"] = 0,
				["s28"] = 0,
				["Palkintoo"] = 0,
				["RARE"] = 0,
				["EPIC"] = 0,
				["NoHot"] = 0,
				["Coinu"] = 0,
				["Luckyu"] = 0,
				["VIPASS"] = 0,
				["ic1"] = 0,
				["ic2"] = 0,
				["ic3"] = 0,
				["ic4"] = 0,
				["ic5"] = 0,
				["ic6"] = 0,
				["ic7"] = 0,
				["ic8"] = 0,
				["ic9"] = 0,
				["ic10"] = 0,
				["ic11"] = 0,
				["FK"] = 0,
				["k51"] = 0,
				["k52"] = 0,
				["k53"] = 0,
				["k54"] = 0,
				["k55"] = 0,
				["TT"] = 0,
				["TT2"] = 0,
				["TT3"] = 0,
				["vspeed"] = 0,
				["vshop"] = 0,
				["vtp"] = 0,
				["vtask"] = 0,
				["vinv"] = 0,
				["vshadow"] = 0,
				["vmusic"] = 0,
				["venv"] = 0,
				["vbrightness"] = 0,
				["vtrade"] = 0,
				["vstyle"] = 0,
				["vlow"] = 0,
				["et11"] = 0,
				["mraha11"] = 0,
				["mraha21"] = 0,
				["mraha31"] = 0,
				["raha1"] = 0,
				["r2aha1"] = 0,
				["r3aha1"] = 0,
				["hr1aha"] = 0,
				["hr2aha"] = 0,
				["hr3aha"] = 0,
				["iraha11"] = 0,
				["iraha21"] = 0,
				["iraha31"] = 0,
				["raha2"] = 0,
				["raha3"] = 0,
				["raha4"] = 0,
				["et22"] = 0,
				["et33"] = 0,
				["mt1"] = 0,
				["mt2"] = 0,
				["mt3"] = 0,
				["ht1"] = 0,
				["ht2"] = 0,
				["ht3"] = 0,
				["it1"] = 0,
				["it2"] = 0,
				["it3"] = 0,
				["t1"] = 0,
				["t2"] = 0,
				["t3"] = 0,
				["t4"] = 0,
				["t5"] = 0,
				["t6"] = 0,
				["t7"] = 0,
				["t8"] = 0,
				["t9"] = 0,
				["Inv2"] = 0,
				["Inv3"] = 0,
				["t10"] = 0,
				["t11"] = 0,
				["DailyB"] = 0,
				["REBIRTH"] = 0,
				["REBIRTHT"] = 0,
				["Speedu"] = 0,
				["LEGENDARY"] = 0,
				["EXCLUSIVE"] = 0
			}

		end
		sessionData[player.UserId] = playerData
		print("toimii1")
	else
		warn("Unable to get data for", player.UserId)
		player:Kick("Unable to load your data. Try again later")
	end

	dollars.Value = sessionData[player.UserId]["Dollars"]
	
	gems.Value = sessionData[player.UserId]["Gems"]
	vipass.Value = sessionData[player.UserId]["VIPASS"]
	tt.Value = sessionData[player.UserId]["TT"]
	ttt2.Value = sessionData[player.UserId]["TT2"]
	ttt3.Value = sessionData[player.UserId]["TT3"]
	saunapower.Value = sessionData[player.UserId]["saunapower"]
	
	
	

	
	vspeed.Value = sessionData[player.UserId]["vspeed"]
	vshop.Value = sessionData[player.UserId]["vshop"]
	vtp.Value = sessionData[player.UserId]["vtp"]
	vtask.Value = sessionData[player.UserId]["vtask"]
	vinv.Value = sessionData[player.UserId]["vinv"]
	vshadow.Value = sessionData[player.UserId]["vshadow"]
	vlow.Value = sessionData[player.UserId]["vlow"]
	vtrade.Value = sessionData[player.UserId]["vtrade"]
	vstyle.Value = sessionData[player.UserId]["vstyle"]
	venv.Value = sessionData[player.UserId]["venv"]
	vbrightness.Value = sessionData[player.UserId]["vbrightness"]
	vmusic.Value = sessionData[player.UserId]["vmusic"]
	
	
	
	
	sbutton.Value = sessionData[player.UserId]["s1"]
	scoin.Value = sessionData[player.UserId]["s2"]
	scrown.Value = sessionData[player.UserId]["s3"]
	sdaily.Value = sessionData[player.UserId]["s4"]
	sdailyopen.Value = sessionData[player.UserId]["s5"]
	sdeath.Value = sessionData[player.UserId]["s6"]
	seasy.Value = sessionData[player.UserId]["s7"]
	sepic.Value = sessionData[player.UserId]["s8"]
	sexclusive.Value = sessionData[player.UserId]["s9"]
	sgem.Value = sessionData[player.UserId]["s10"]
	sgemspent.Value = sessionData[player.UserId]["s11"]
	shard.Value = sessionData[player.UserId]["s12"]
	simpossible.Value = sessionData[player.UserId]["s13"]
	sjoined1.Value = sessionData[player.UserId]["s14"]
	sjoined2.Value = sessionData[player.UserId]["s15"]
	sjoined3.Value = sessionData[player.UserId]["s16"]
	slegendary.Value = sessionData[player.UserId]["s17"]
	smedium.Value = sessionData[player.UserId]["s18"]
	srare.Value = sessionData[player.UserId]["s19"]
	srebirth.Value = sessionData[player.UserId]["s20"]
	srobux.Value = sessionData[player.UserId]["s21"]
	stime.Value = sessionData[player.UserId]["s22"]
	stotaltask.Value = sessionData[player.UserId]["s23"]
	strade.Value = sessionData[player.UserId]["s24"]
	swin.Value = sessionData[player.UserId]["s25"]

	
	


	
	
	
	et1.Value = sessionData[player.UserId]["et11"]
	print(sessionData[player.UserId]["et1"])
	eraha.Value = sessionData[player.UserId]["raha1"]
	eraha2.Value = sessionData[player.UserId]["r2aha1"]
	eraha3.Value = sessionData[player.UserId]["r3aha1"]
	mraha.Value = sessionData[player.UserId]["mraha11"]
	mraha2.Value = sessionData[player.UserId]["mraha21"]
	mraha3.Value = sessionData[player.UserId]["mraha31"]
	hraha.Value = sessionData[player.UserId]["hr1aha"]
	hraha2.Value = sessionData[player.UserId]["hr2aha"]
	hraha3.Value = sessionData[player.UserId]["hr3aha"]
	iraha.Value = sessionData[player.UserId]["iraha11"]
	iraha2.Value = sessionData[player.UserId]["iraha21"]
	iraha3.Value = sessionData[player.UserId]["iraha31"]
	et2.Value = sessionData[player.UserId]["et22"]
	et3.Value = sessionData[player.UserId]["et33"]
	mt1.Value = sessionData[player.UserId]["mt1"]
	mt2.Value = sessionData[player.UserId]["mt2"]
	mt3.Value = sessionData[player.UserId]["mt3"]
	ht1.Value = sessionData[player.UserId]["ht1"]
	ht2.Value = sessionData[player.UserId]["ht2"]
	ht3.Value = sessionData[player.UserId]["ht3"]
	it1.Value = sessionData[player.UserId]["it1"]
	it2.Value = sessionData[player.UserId]["it2"]
	it3.Value = sessionData[player.UserId]["it3"]
	
	tr1.Value = sessionData[player.UserId]["t1"]
	tr2.Value = sessionData[player.UserId]["t2"]
	tr3.Value = sessionData[player.UserId]["t3"]
	tr4.Value = sessionData[player.UserId]["t4"]
	ts1.Value = sessionData[player.UserId]["t5"]
	ts2.Value = sessionData[player.UserId]["t6"]
	te1.Value = sessionData[player.UserId]["t7"]
	te2.Value = sessionData[player.UserId]["t8"]
	tl1.Value = sessionData[player.UserId]["t9"]
	tl2.Value = sessionData[player.UserId]["t10"]
	tm.Value = sessionData[player.UserId]["t11"]
	inv2.Value = sessionData[player.UserId]["Inv2"]
	inv3.Value = sessionData[player.UserId]["Inv3"]
	
	loaded.Value = 2
	crowns.Value = sessionData[player.UserId]["Crown"]
	loaded.Value = 3
	coinup.Value = sessionData[player.UserId]["Coinu"]
	loaded.Value = 4
	print(coinup.Value)
	print(sessionData[player.UserId]["Coinu"])
	print("et1 value: " .. et1.Value)
	print("et1: " .. sessionData[player.UserId]["et11"])
	print("et2 value: " .. et1.Value)
	print("et2: " .. sessionData[player.UserId]["et22"])
	print("et3 value: " .. et1.Value)
	print("et3: " .. sessionData[player.UserId]["et33"])
	speedup.Value = sessionData[player.UserId]["Speedu"]
	rebirth.Value = sessionData[player.UserId]["REBIRTH"]
	rebirtht.Value = sessionData[player.UserId]["REBIRTHT"]
	loaded.Value = 5
	freekiulup.Value = sessionData[player.UserId]["FK"]
	loaded.Value = 6
	nohotup.Value = sessionData[player.UserId]["NoHot"]
	loaded.Value = 7
	luckyup.Value = sessionData[player.UserId]["Luckyu"]
	loaded.Value = 8
	sauna2.Value = sessionData[player.UserId]["Sauna2"]
	loaded.Value = 9
	sauna3.Value = sessionData[player.UserId]["Sauna3"]
	loaded.Value = 10
	sauna4.Value = sessionData[player.UserId]["Sauna4"]
	loaded.Value = 11
	sauna5.Value = sessionData[player.UserId]["Sauna5"]
	loaded.Value = 12
	sauna6.Value = sessionData[player.UserId]["Sauna6"]
	loaded.Value = 13
	sauna7.Value = sessionData[player.UserId]["Sauna7"]
	loaded.Value = 14
	sauna8.Value = sessionData[player.UserId]["Sauna8"]
	loaded.Value = 15
	
	sauna9.Value = sessionData[player.UserId]["Sauna9"]
	
	sauna11.Value = sessionData[player.UserId]["Sauna11"]
	loaded.Value = 16
	k51.Value = sessionData[player.UserId]["k51"]
	loaded.Value = 17
	k52.Value = sessionData[player.UserId]["k52"]
	k53.Value = sessionData[player.UserId]["k53"]
	k54.Value = sessionData[player.UserId]["k54"]
	k55.Value = sessionData[player.UserId]["k55"]
	loaded.Value = 18
	ranta.Value = sessionData[player.UserId]["Ranta"]

	laava.Value = sessionData[player.UserId]["Laava"]

	pelipalkinto.Value = sessionData[player.UserId]["palkintoo"]
	loaded.Value = 19
	rare.Value = sessionData[player.UserId]["RARE"]
	
	epic.Value = sessionData[player.UserId]["EPIC"]
	
	dailyb.Value = sessionData[player.UserId]["DailyB"]
	
	legendary.Value = sessionData[player.UserId]["LEGENDARY"]
	exclusive.Value = sessionData[player.UserId]["EXCLUSIVE"]
	vipass.Changed:Connect(function()
		sessionData[player.UserId].VIPASS = vipass.Value
		print("vipass")
		
	end)
	if sjoined1.Value == 0 then
		if not playerData then
			warn("ERROR with getting date")
		else
			local onnistu, vika = pcall(function()
			sjoined1.Value = 9
			sjoined2.Value = 18
			sjoined3.Value = 2022
			sessionData[player.UserId].s14 = sjoined1.Value
			sessionData[player.UserId].s14 = sjoined2.Value
			sessionData[player.UserId].s14 = sjoined3.Value
			end)
			if not onnistu then
				warn("jaahas... " .. vika)
			end
		end

	end
	
	saunapower.Changed:Connect(function()
		sessionData[player.UserId].saunapower = saunapower.Value
	end)

	
	
	
	ttt2.Changed:Connect(function()
		sessionData[player.UserId].TT2 = ttt2.Value
	end)
	
	ttt3.Changed:Connect(function()
		sessionData[player.UserId].TT3 = ttt3.Value
	end)
	
	vspeed.Changed:Connect(function()
		sessionData[player.UserId].vspeed = vspeed.Value
	end)
	
	vshop.Changed:Connect(function()
		sessionData[player.UserId].vshop = vshop.Value
	end)
	
	vtp.Changed:Connect(function()
		sessionData[player.UserId].vtp = vtp.Value
	end)
	
	vtask.Changed:Connect(function()
		sessionData[player.UserId].vtask = vtask.Value
	end)
	
	vinv.Changed:Connect(function()
		sessionData[player.UserId].vinv = vinv.Value
	end)
	
	vshadow.Changed:Connect(function()
		sessionData[player.UserId].vshadow = vshadow.Value
	end)
	
	vtrade.Changed:Connect(function()
		sessionData[player.UserId].vtrade = vtrade.Value
	end)
	
	vstyle.Changed:Connect(function()
		sessionData[player.UserId].vstyle = vstyle.Value
	end)
	
	vlow.Changed:Connect(function()
		sessionData[player.UserId].vlow = vlow.Value
	end)
	
	venv.Changed:Connect(function()
		sessionData[player.UserId].venv = venv.Value
	end)
	
	vmusic.Changed:Connect(function()
		sessionData[player.UserId].vmusic = vmusic.Value
	end)
	
	vbrightness.Changed:Connect(function()
		sessionData[player.UserId].vbrightness = vbrightness.Value
	end)
	




	
	
	
	
	sbutton.Changed:Connect(function()
		sessionData[player.UserId].s1 = sbutton.Value
	end)
	scoin.Changed:Connect(function()
		sessionData[player.UserId].s2 = scoin.Value
	end)
	scrown.Changed:Connect(function()
		sessionData[player.UserId].s3 = scrown.Value
	end)
	sdaily.Changed:Connect(function()
		sessionData[player.UserId].s4 = sdaily.Value
	end)
	sdailyopen.Changed:Connect(function()
		sessionData[player.UserId].s5 = sdailyopen.Value
	end)
	sdeath.Changed:Connect(function()
		sessionData[player.UserId].s6 = sdeath.Value
	end)
	seasy.Changed:Connect(function()
		sessionData[player.UserId].s7 = seasy.Value
	end)
	sepic.Changed:Connect(function()
		sessionData[player.UserId].s8 = sepic.Value
	end)
	sexclusive.Changed:Connect(function()
		sessionData[player.UserId].s9 = sexclusive.Value
	end)
	sgem.Changed:Connect(function()
		sessionData[player.UserId].s10 = sgem.Value
	end)
	sgemspent.Changed:Connect(function()
		sessionData[player.UserId].s11 = sgemspent.Value
	end)
	shard.Changed:Connect(function()
		sessionData[player.UserId].s12 = shard.Value
	end)
	simpossible.Changed:Connect(function()
		sessionData[player.UserId].s13 = simpossible.Value
	end)
	sjoined1.Changed:Connect(function()
		sessionData[player.UserId].s14 = sjoined1.Value
	end)
	sjoined2.Changed:Connect(function()
		sessionData[player.UserId].s15 = sjoined2.Value
	end)
	sjoined3.Changed:Connect(function()
		sessionData[player.UserId].s16 = sjoined3.Value
	end)
	slegendary.Changed:Connect(function()
		sessionData[player.UserId].s17 = slegendary.Value
	end)
	smedium.Changed:Connect(function()
		sessionData[player.UserId].s18 = smedium.Value
	end)
	srare.Changed:Connect(function()
		sessionData[player.UserId].s19 = srare.Value
	end)
	srebirth.Changed:Connect(function()
		sessionData[player.UserId].s20 = srebirth.Value
	end)
	srobux.Changed:Connect(function()
		sessionData[player.UserId].s21 = srobux.Value
	end)
	stime.Changed:Connect(function()
		sessionData[player.UserId].s22 = stime.Value
	end)
	stotaltask.Changed:Connect(function()
		sessionData[player.UserId].s23 = stotaltask.Value
	end)
	strade.Changed:Connect(function()
		sessionData[player.UserId].s24 = strade.Value
	end)
	swin.Changed:Connect(function()
		sessionData[player.UserId].s25 = swin.Value
	end)







	
	
	
	eraha.Changed:Connect(function()
		sessionData[player.UserId].raha1 = eraha.Value
		
		print("eraha")
		et1.Value = 0
		sessionData[player.UserId].et11 = et1.Value
		print("et1")


	end)
	eraha2.Changed:Connect(function()
		sessionData[player.UserId].r2aha1  = eraha2.Value
		
		print("eraha2")
		et2.Value = 0
		sessionData[player.UserId].et22 = et2.Value
		print("et2")
	end)
	
	eraha3.Changed:Connect(function()
		sessionData[player.UserId].r3aha1 = eraha3.Value
		
		print("eraha3")
		et3.Value = 0
		sessionData[player.UserId].et33 = et3.Value
		print("et3")
	end)

	mraha.Changed:Connect(function()
		sessionData[player.UserId].mraha11 = mraha.Value
		
		print("mraha")
		mt1.Value = 0
		sessionData[player.UserId].mt1 = mt1.Value
		print("mt1")
		
	end)
	mraha2.Changed:Connect(function()
		sessionData[player.UserId].mraha21 = mraha2.Value
		
		print("mraha2")
		mt2.Value = 0
		sessionData[player.UserId].mt2 = mt2.Value
		print("mt2")
	end)
	mraha3.Changed:Connect(function()
		sessionData[player.UserId].mraha31 = mraha3.Value
		
		print("mraha3")
		mt3.Value = 0
		sessionData[player.UserId].mt3 = mt3.Value
		print("mt3")
	end)

	hraha.Changed:Connect(function()
		sessionData[player.UserId].hr1aha = hraha.Value
		print("hraha1")
		ht1.Value = 0
		sessionData[player.UserId].ht1 = ht1.Value
		print("ht1")
	end)
	
	hraha2.Changed:Connect(function()
		sessionData[player.UserId].hr2aha = hraha2.Value
		print("hraha2")
		ht2.Value = 0
		sessionData[player.UserId].ht2 = ht2.Value
		print("ht2")
	end)
	
	hraha3.Changed:Connect(function()
		sessionData[player.UserId].hr3aha = hraha3.Value
		print("hraha3")
		ht3.Value = 0
		sessionData[player.UserId].ht3 = ht3.Value
		print("ht3")
	end)

	iraha.Changed:Connect(function()
		sessionData[player.UserId].iraha11 = iraha.Value
		print("iraha")
		it1.Value = 0
		sessionData[player.UserId].it1 = it1.Value
	end)
	iraha2.Changed:Connect(function()
		sessionData[player.UserId].iraha21 = iraha2.Value
		print("iraha2")
		it2.Value = 0
		sessionData[player.UserId].it2 = it2.Value
	end)
	iraha3.Changed:Connect(function()
		sessionData[player.UserId].iraha31 = iraha3.Value
		print("iraha3")
		it3.Value = 0
		sessionData[player.UserId].it3 = it3.Value
	end)
	
	et1.Changed:Connect(function()
		sessionData[player.UserId].et11 = et1.Value
		print("et1")
		print("et1: " .. sessionData[player.UserId]["et11"])
		print("et2 value: " .. et1.Value)
		print("et2: " .. sessionData[player.UserId]["et22"])
		print("et3 value: " .. et1.Value)
		print("et3: " .. sessionData[player.UserId]["et33"])
	end)
	
	et2.Changed:Connect(function()
		sessionData[player.UserId].et22 = et2.Value
		print("et2")
		print("et1: " .. sessionData[player.UserId]["et11"])
		print("et2 value: " .. et1.Value)
		print("et2: " .. sessionData[player.UserId]["et22"])
		print("et3 value: " .. et1.Value)
		print("et3: " .. sessionData[player.UserId]["et33"])
	end)

	et3.Changed:Connect(function()
		sessionData[player.UserId].et33 = et3.Value
		print("et3")
		print("et1: " .. sessionData[player.UserId]["et11"])
		print("et2 value: " .. et1.Value)
		print("et2: " .. sessionData[player.UserId]["et22"])
		print("et3 value: " .. et1.Value)
		print("et3: " .. sessionData[player.UserId]["et33"])
	end)
	

	mt1.Changed:Connect(function()
		sessionData[player.UserId].mt1 = mt1.Value
		print("mt1")
	end)

	mt2.Changed:Connect(function()
		sessionData[player.UserId].mt2 = mt2.Value
		print("mt2")
	end)

	mt3.Changed:Connect(function()
		sessionData[player.UserId].mt3 = mt3.Value
		print("mt3")
	end)

	ht1.Changed:Connect(function()
		sessionData[player.UserId].ht1 = ht1.Value
		
	end)
	
	ht2.Changed:Connect(function()
		sessionData[player.UserId].ht2 = ht2.Value
		
	end)
	
	ht3.Changed:Connect(function()
		sessionData[player.UserId].ht3 = ht3.Value
		
		
	end)
	
	it1.Changed:Connect(function()
		sessionData[player.UserId].it1 = it1.Value
		print("it1")
	end)
	

	it2.Changed:Connect(function()
		sessionData[player.UserId].it2 = it2.Value
		print("it2")
	end)
	

	it3.Changed:Connect(function()
		sessionData[player.UserId].it3 = it3.Value
		print("it3")
	end)
	
	rebirth.Changed:Connect(function()
		sessionData[player.UserId].REBIRTH = rebirth.Value
		print("rebirth")

	end)
	rebirtht.Changed:Connect(function()
		sessionData[player.UserId].REBIRTHT = rebirtht.Value
		print("rebirthtoken")
		

	end)
	dollars.Changed:Connect(function()
		sessionData[player.UserId].Dollars = dollars.Value
		print("raha")
		

	end)
	crowns.Changed:Connect(function()
		sessionData[player.UserId].Crown = crowns.Value
		print("kruunu")
		

	end)
	inv2.Changed:Connect(function()
		sessionData[player.UserId].Inv2 = inv2.Value
		print("inv2")

	end)
	inv3.Changed:Connect(function()
		sessionData[player.UserId].Inv3 = inv3.Value
		print("inv3")

	end)
	gems.Changed:Connect(function()
		sessionData[player.UserId].Gems = gems.Value
		print("gem")
		

	end)
	nohotup.Changed:Connect(function()
		sessionData[player.UserId].NoHot = nohotup.Value
		print("nohotu")

	end)
	coinup.Changed:Connect(function()
		sessionData[player.UserId].Coinu = coinup.Value
		print("coinup")

	end)
	k51.Changed:Connect(function()
		sessionData[player.UserId].k51 = k51.Value
		print("k51")

	end)
	
	
	k52.Changed:Connect(function()
		sessionData[player.UserId].k52 = k52.Value
		print("k52")
	end)
	
	dailyb.Changed:Connect(function()
		sessionData[player.UserId].DailyB = dailyb.Value
		print("DAILYYYYYY")
	end)

	k53.Changed:Connect(function()
		sessionData[player.UserId].k53 = k53.Value
		print("k53")
	end)

	k54.Changed:Connect(function()
		sessionData[player.UserId].k54 = k54.Value
		print("k54")
	end)

	k55.Changed:Connect(function()
		sessionData[player.UserId].k55 = k55.Value
		print("k55")
	end)
	
	tt.Changed:Connect(function()
		sessionData[player.UserId].TT = tt.Value
		print("tt")
	end)
	
	tr1.Changed:Connect(function()
		sessionData[player.UserId].t1 = tr1.Value
		print("tr1")
	end)
	
	tr2.Changed:Connect(function()
		sessionData[player.UserId].t2 = tr2.Value
		print("tr2")
	end)
	
	tr3.Changed:Connect(function()
		sessionData[player.UserId].t3 = tr3.Value
		print("tr3")
	end)
	
	tr4.Changed:Connect(function()
		sessionData[player.UserId].t4 = tr4.Value
		print("tr4")
	end)
	
	ts1.Changed:Connect(function()
		sessionData[player.UserId].t5 = ts1.Value
		print("ts1")
	end)
	
	ts2.Changed:Connect(function()
		sessionData[player.UserId].t6 = ts2.Value
		print("ts2")
	end)
	
	te1.Changed:Connect(function()
		sessionData[player.UserId].t7 = te1.Value
		print("te1")
	end)
	
	te2.Changed:Connect(function()
		sessionData[player.UserId].t8 = te2.Value
		print("te2")
	end)
	
	tl1.Changed:Connect(function()
		sessionData[player.UserId].t9 = tl1.Value
		print("tl1")
	end)
	
	tl2.Changed:Connect(function()
		sessionData[player.UserId].t10 = tl2.Value
		print("tl2")
	end)
	
	tm.Changed:Connect(function()
		sessionData[player.UserId].t11 = tm.Value
		print("tm")
	end)


	speedup.Changed:Connect(function()
		sessionData[player.UserId].Speedu = speedup.Value
		print("speedu")

	end)
	luckyup.Changed:Connect(function()
		sessionData[player.UserId].Luckyu = luckyup.Value
		print("luckyu")

	end)
	freekiulup.Changed:Connect(function()
		sessionData[player.UserId].FK = freekiulup.Value
		print("freekiulu")

	end)
	sauna2.Changed:Connect(function()
		sessionData[player.UserId].Sauna2 = sauna2.Value
		print("sauna2")


	end)
	sauna3.Changed:Connect(function()
		sessionData[player.UserId].Sauna3 = sauna3.Value
		print("sauna3")


	end)
	
	sauna4.Changed:Connect(function()
		sessionData[player.UserId].Sauna4 = sauna4.Value
		print("sauna4")


	end)
	
	sauna5.Changed:Connect(function()
		sessionData[player.UserId].Sauna5 = sauna5.Value
		print("sauna5")


	end)
	
	sauna6.Changed:Connect(function()
		sessionData[player.UserId].Sauna6 = sauna6.Value
		print("sauna6")


	end)
	
	sauna7.Changed:Connect(function()
		sessionData[player.UserId].Sauna7 = sauna7.Value
		print("sauna7")


	end)
	

	sauna8.Changed:Connect(function()
		sessionData[player.UserId].Sauna8 = sauna8.Value
		print("sauna8")


	end)
	
	sauna9.Changed:Connect(function()
		sessionData[player.UserId].Sauna9 = sauna9.Value
		print("sauna9")


	end)
	
	sauna11.Changed:Connect(function()
		sessionData[player.UserId].Sauna11 = sauna11.Value
		print("sauna11")


	end)
	
	pelipalkinto.Changed:Connect(function()
		sessionData[player.UserId].pelipalkintoo = pelipalkinto.Value
		print("free gift!")

	end)
	
	
	ranta.Changed:Connect(function()
		sessionData[player.UserId].Ranta = ranta.Value
		print("ranta")

	end)
	
	laava.Changed:Connect(function()
		sessionData[player.UserId].Laava = laava.Value
		print("laava")

	end)
	print("PLR:" .. player.Name)
	load.Parent = player
	loaded.Value = 20
	leaderstats.Parent = player
	saunat.Parent = player
	alueet.Parent = player
	Koodit.Parent = player
	palkintoja.Parent = player
	boksit.Parent = player
	lvl.Parent = player
	setting.Parent = player
	stat.Parent = player
	load.Parent = player
	rebirthf.Parent = player
	titlet.Parent = player
	inv.Parent = player
	tasks.Parent = player
	gui.Parent = player
	fff.Parent = player
	passi.Parent = player
	wait(4)
	loaded.Value = 21
	wait(1)
	loaded.Value = 22
	wait(.5)
	loaded.Value = 23
	wait(.5)
	loaded.Value = 24
	wait(.5)
	loaded.Value = 25
end


Players.PlayerAdded:Connect(PlayerAdded)

function PlayerLeaving(player)
	if sessionData[player.UserId] then
		local success = nil
		local errorMsg = nil
		local attempt = 1

		repeat
			success, errorMsg = pcall(function()
				print("toimii5")
				database:SetAsync(player.UserId, sessionData[player.UserId])
			end)
			attempt += 1
			if not success then
				warn(errorMsg)
				task.wait(3)
			end
		until success or attempt == 5

		if success then
			print("Data saved for", player.Name)
		else
			warn("Unable to save for", player.Name)
		end

	end

end

Players.PlayerRemoving:Connect(PlayerLeaving)

function ServerShutdown()
	if RunService:IsStudio() then
		print("toimiiSTUDIO")
		return 
	end
	print("Server shutting down...")
	for _, player in pairs(Players:GetPlayers()) do
		task.spawn(function()
			PlayerLeaving(player)
		end)
	end
end
game:BindToClose(ServerShutdown)

Please help me.

I did not include everything because of the amount of data in your code, but assigning data in that way is very inefficient and a huge waste of time. Instead I recommend taking a look at using more tables

I would do something like this example as it is way faster and keeps you from going insane

Note: “for i,v in next, table do” is about the same as “for i,v in table do” so dont get confused about that :​p

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")

local database = DataStoreService:GetDataStore("MyDataStore")
local sessionData = {}

local ValueTypes = {
	number = "NumberValue",
	string = "StringValue",
	boolean = "BoolValue",
}

local Data = {
	settings = {
		speed = 0,
		shop = 0,
		inventory = 0,
		task = 0,
		tp = 0,
		low = 0,
		shadow = 0,
		style = 0,
		brightness = 0,
		music = 0,
		environment = 0,
		trade = 0,
	},

	stats = {
		button = 0,
		coin = 0,
		crown = 0,
		daily = 0,
		dailyopen = 0,
		death = 0,
		easy = 0,
		epic = 0,
		legendary = 0,
		medium = 0,
		rare = 0,
		exclusive = 0,
		gem = 0,
		gemspent = 0,
		hard = 0,
		impossible = 0,

		--joined1 = 0,
		--joined2 = 0,
		--joined3 = 0, idk what these were for but you can probably figure out where to place them
		rebirth = 0,
		robux = 0,
		time = 0,
		totaltask = 0,
		trade = 0,
		win = 0,
	}
}

local DefaultPlayerData = {
	Dollars = 0,
	Gems = 0,
	Crown = 0,
	Sauna2 = 0,
	Sauna3 = 0,
	Sauna4 = 0,
	Sauna5 = 0,
	Sauna6 = 0,
	Sauna7 = 0,
	Sauna8 = 0,
	Sauna9 = 0,
	Sauna11 = 0,
	Ranta = 0,
	Laava = 0,
	saunapower = 0,
	Palkintoo = 0,
	RARE = 0,
	EPIC = 0,
	NoHot = 0,
	Coinu = 0,
	Luckyu = 0,
	VIPASS = 0,
	vspeed = 0,
	vshop = 0,
	vtp = 0,
	vtask = 0,
	vinv = 0,
	vshadow = 0,
	vmusic = 0,
	venv = 0,
	vbrightness = 0,
	vtrade = 0,
	vstyle = 0,
	vlow = 0,
	DailyB = 0,
	REBIRTH = 0,
	REBIRTHT = 0,
	Speedu = 0,
	LEGENDARY = 0,
	EXCLUSIVE = 0,
}


function PlayerAdded(player)
	repeat
		success, playerData = pcall(function()
			print("toimii")
			return database:GetAsync(player.UserId)
		end)


		attempt += 1
		if not success then
			warn(playerData)
			loaded.Value = 1
			task.wait(3)
		end
	until success or attempt == 5
	if success then
		print("Connected to database")
		if not playerData then
			print("Assigning default data")
			playerData = table.clone(DefaultPlayerData)
		end
		sessionData[player.UserId] = playerData
		print("toimii1")
	else
		warn("Unable to get data for", player.UserId)
		player:Kick("Unable to load your data. Try again later")
	end

	local PlayerData = sessionData[player.UserId]

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local function recursion(folderChildren, folder)
		for name, value in next, folderChildren do
			local ValueType = type(value)
			if (ValueType ~= "table") then
				local InstanceName = ValueTypes[ValueType]
				if (InstanceName) then
					local ValueInstance = Instance.new(InstanceName, folder)
					ValueInstance.Name = name
					ValueInstance.Value = PlayerData[name] and PlayerData[name] or value
					ValueInstance.Changed:Connect(function(NewValue) --Note that changed always returns the new value, but this is only the case for Value Instances (such as numbervalue)
						PlayerData[name] = NewValue
					end) --There is a better way of doing this, connecting this many functions isn't very good but it works
					--[[
					the line above is the same as this
					if (PlayerData[name]) then
						ValueInstance.Value = PlayerData[name]
					else
						ValueInstance.Value = value
					end
					]]
				end
			else
				recursion(value, folder) --This is here in case you want to add more subdirectories to your data
			end
		end
	end

	for folderName, folderChildren in next, Data do
		if (type(folderChildren) == "table") then
			local folder = Instance.new("Folder", leaderstats) --here it doesn't matter when we assign the parent since the parent we're assigning it to is already unassigned (nil)
			folder.Name = folderName                           --but in general when assigning an instance to a parent you should assign all other properties before assigning the parent
			
			recursion(folderChildren, folder)
		end
	end
end
1 Like

Okay, thank you for doing that for me, but I need the answer to this question: Why doesn’t my datastore work anymore? I have a second datastore script, and it works normally. It has the same mechanics as this datastore script.

this is probably due to some if statement where it returns true even if the player doesnt have any saved data

1 Like

Thanks!

It works now. I still have one problem to solve but I think I can solve it on my own.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.