(Note: game is filtered enabled) (Note: output says 'Script_Variables.dataStore:50: '' expected near 'end') (Note: i dont really understand datastores)


local DS = game:GetService('DataStoreService'):GetDataStore('Bloxel Studios')
local StatFile = game:GetService('ServerStorage'):WaitForChild('StatFile')

game.Players.PlayerAdded:Connect(function(player)
	local playerFolder = Instance.new('Folder', StatFile)
	playerFolder.Name = player.Name
	
	local playerStats = Instance.new('Folder', StatFile)
	playerStats.Name = 'playerStats'
	
	local playerLevel = Instance.new('IntValue', playerStats)
	playerLevel.Name = 'playerLevel'
	playerLevel.Value = 0
	
	local playerCol = Instance.new('IntValue', playerStats)
	playerCol.Name = 'playerCol'
	playerCol.Value = 0
	
	local playerExp = Instance.new('IntValue', playerStats)
	playerExp.Name = 'playerExp'
	playerExp.Value = 0
	
	local playerStr = Instance.new('IntValue', playerStats)
	playerStr.Name = 'playerStr'
	playerCol.Value = 0
	
	
	local playerAgi = Instance.new('IntValue', playerStats)
	playerAgi.Name = 'playerAgi'
	playerAgi.Value = 0
	
	local playerStm = Instance.new('IntValue', playerStats)
	playerStm.Name = 'playerStm'
	playerStm.Value = 0
	
	
	local playerDex = Instance.new('IntValue', playerStats)
	playerDex.Name = 'playerDex'
	playerDex.Value = 0
	
	local playerVit = Instance.new('IntValue', playerStats)
	playerVit.Name = 'playerVit'
	playerVit.Value = 0
	
	local playerOneHandSword = Instance.new('IntValue', playerStats)
	playerOneHandSword.Name = 'playerOneHandSword'
	playerOneHandSword.Value = 0
	
	local playerTwoHandSword = Instance.new('IntValue', playerStats)
	playerTwoHandSword.Name = 'playerTwoHandSword'
	playerTwoHandSword.Value = 0
	
	local playerRapier = Instance.new('IntValue', playerStats)
	playerRapier.Name = 'playerRapier'
	playerRapier.Value = 0
	
	local playerSmithing = Instance.new('IntValue', playerStats)
	playerSmithing.Name = 'playerSmithing'
	playerSmithing.Value = 0
	
	local playerCooking = Instance.new('IntValue', playerStats)
	playerCooking.Name = 'playerCooking'
	playerCooking.Value = 0
	
	local thing = Instance.new('BoolValue', playerStats)
	thing.Name = 'thing'
	
	local str = Instance.new('StringValue', playerStats)
	str.Name = 'str'
	
	
	local savedStuff = DS:GetAsync(player.UserId)
	
	if savedStuff then
		print(game:GetService("HttpService"):JSONEncode(savedStuff):len())		
		for i, v in pairs(savedStuff) do
			print(i,v)
			if i % 2 == 0 then
				StatFile[player.Name].playerStats:FindFirstChild(savedStuff[i - 1]).Value = v
			end
		end		
	end	
end)

local function saveValues(player)
	local savedData = {}
	for i, v in pairs(StatFile[player.Name].playerStats:GetChildren()) do
		savedData[#savedData + 1] = v.Name
		savedData[#savedData - 1] = v.Value
	end
end

game:BindToClose(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		saveValues(player)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	saveValues(player)
end)